class CommunityZero::Metadata

A quick, short metadata parser.

@author Seth Vargo <sethvargo@gmail.com>

Public Class Methods

from_json(content) click to toggle source

Create a new metadata class from the JSON.

@param [String] content

the raw JSON content to parse into metadata
# File lib/community_zero/chef/metadata.rb, line 30
def self.from_json(content)
  json = JSON.parse(content)

  new.tap do |instance|
    json.each do |k,v|
      instance.send(k, v)
    end
  end
end
from_ruby(content) click to toggle source

Create a new metadata class from the raw Ruby.

@param [String] content

the contents of the file to convert to a metadata entry
# File lib/community_zero/chef/metadata.rb, line 44
def self.from_ruby(content)
  new.tap do |instance|
    instance.instance_eval(content)
  end
end

Public Instance Methods

method_missing(m, *args, &block) click to toggle source
# File lib/community_zero/chef/metadata.rb, line 50
def method_missing(m, *args, &block)
  if args.empty?
    data[m.to_sym]
  else
    data[m.to_sym] = args.size == 1 ? args[0] : args
  end
end
respond_to?(m) click to toggle source
# File lib/community_zero/chef/metadata.rb, line 58
def respond_to?(m)
  !!data[m.to_sym]
end

Private Instance Methods

data() click to toggle source
# File lib/community_zero/chef/metadata.rb, line 63
def data
  @data ||= {}
end