Class: CommunityZero::Metadata
- Inherits:
-
Object
- Object
- CommunityZero::Metadata
- Defined in:
- lib/community_zero/chef/metadata.rb
Overview
A quick, short metadata parser.
Class Method Summary collapse
-
.from_json(content) ⇒ Object
Create a new metadata class from the JSON.
-
.from_ruby(content) ⇒ Object
Create a new metadata class from the raw Ruby.
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
50 51 52 53 54 55 56 |
# 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 |
Class Method Details
.from_json(content) ⇒ Object
Create a new metadata class from the JSON.
30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
Create a new metadata class from the raw Ruby.
44 45 46 47 48 |
# File 'lib/community_zero/chef/metadata.rb', line 44 def self.from_ruby(content) new.tap do |instance| instance.instance_eval(content) end end |
Instance Method Details
#respond_to?(m) ⇒ Boolean
58 59 60 |
# File 'lib/community_zero/chef/metadata.rb', line 58 def respond_to?(m) !!data[m.to_sym] end |