Class: Toft::ChefAttributes
- Inherits:
-
Object
- Object
- Toft::ChefAttributes
- Defined in:
- lib/toft/chef/chef_attributes.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #add_attribute(key, value) ⇒ Object
-
#initialize(cuke_ast_table = nil) ⇒ ChefAttributes
constructor
A new instance of ChefAttributes.
- #to_json ⇒ Object
Constructor Details
#initialize(cuke_ast_table = nil) ⇒ ChefAttributes
Returns a new instance of ChefAttributes.
7 8 9 10 11 12 |
# File 'lib/toft/chef/chef_attributes.rb', line 7 def initialize(cuke_ast_table = nil) @attributes = {} cuke_ast_table.hashes.each do |row| add_attribute row[:key], row[:value] end unless cuke_ast_table.nil? end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/toft/chef/chef_attributes.rb', line 5 def attributes @attributes end |
Instance Method Details
#add_attribute(key, value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/toft/chef/chef_attributes.rb', line 14 def add_attribute(key, value) stat = "attributes" head = attributes key.split(".").each do |k| head[k] ||= Hash.new head = head[k] stat += "[\"#{k}\"]" end eval "#{stat}=\"#{value}\"" end |
#to_json ⇒ Object
25 26 27 |
# File 'lib/toft/chef/chef_attributes.rb', line 25 def to_json attributes.to_json end |