Class: PoolParty::ChefAttribute
- Defined in:
- lib/poolparty/chef_attribute.rb
Instance Attribute Summary collapse
-
#init_opts ⇒ Object
readonly
Returns the value of attribute init_opts.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(opts = {}, &block) ⇒ ChefAttribute
constructor
A new instance of ChefAttribute.
- #merge!(h = {}) ⇒ Object
- #method_missing(m, *a, &block) ⇒ Object
- #to_dna(recipes, filepath, opts = init_opts) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(opts = {}, &block) ⇒ ChefAttribute
Returns a new instance of ChefAttribute.
4 5 6 7 8 9 |
# File 'lib/poolparty/chef_attribute.rb', line 4 def initialize(opts={}, &block) @init_block = block @init_opts = opts instance_eval &block if block @base_name = self.name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/poolparty/chef_attribute.rb', line 27 def method_missing(m,*a,&block) if @init_opts.has_key?(m) @init_opts[m] else @init_opts.merge!(m => a) end end |
Instance Attribute Details
#init_opts ⇒ Object (readonly)
Returns the value of attribute init_opts.
3 4 5 |
# File 'lib/poolparty/chef_attribute.rb', line 3 def init_opts @init_opts end |
Instance Method Details
#merge!(h = {}) ⇒ Object
11 12 13 |
# File 'lib/poolparty/chef_attribute.rb', line 11 def merge!(h={}) init_opts.merge!(h) end |
#to_dna(recipes, filepath, opts = init_opts) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/poolparty/chef_attribute.rb', line 15 def to_dna(recipes, filepath, opts=init_opts) if recipes && !recipes.empty? (opts[:recipes] ||= []) << recipes opts[:recipes].flatten! end opts.delete(:name) if opts[:name] && opts[:name].empty? File.open(filepath, "w") do |f| f << JSON.pretty_generate(opts) end end |