lib/hibachi/node.rb in hibachi-0.0.1.pre vs lib/hibachi/node.rb in hibachi-0.0.1
- old
+ new
@@ -9,11 +9,11 @@
# write data out to the config file.
class Node
include ActiveModel::Model
include Enumerable
- attr_accessor :attributes, :file_path
+ attr_accessor :file_path
validates :file_path, presence: true
validate :file_exists
validate :has_cookbook_attributes
@@ -43,11 +43,11 @@
# Find the attribute at a given key.
def [] key
attributes[key]
end
- # Set the attribute at a given key.
+ # Set the attribute at a given key and update the JSON.
def []= key, value
merge! key => value
end
# Merge incoming Hash with the Chef JSON.
@@ -72,11 +72,13 @@
# by the global cookbook.
def attributes
@attributes ||= parsed_json_attributes[Hibachi.config.cookbook] || {}
end
- delegate :any?, :to => :attributes
- delegate :empty?, :to => :attributes
+ def method_missing(method, *arguments)
+ attributes.send method, *arguments if attributes.respond_to? method
+ super
+ end
protected
# All attributes as parsed from the Chef JSON.
def parsed_json_attributes
JSON.parse(chef_json).with_indifferent_access