class Ridley::ChefObject
Attributes
resource[R]
Public Class Methods
chef_id()
click to toggle source
@return [String, nil]
# File lib/ridley/chef_object.rb, line 7 def chef_id @chef_id end
chef_json_class()
click to toggle source
@return [String, nil]
# File lib/ridley/chef_object.rb, line 32 def chef_json_class @chef_json_class end
chef_type()
click to toggle source
@return [String]
# File lib/ridley/chef_object.rb, line 19 def chef_type @chef_type ||= self.class.name.underscore end
new(resource, new_attrs = {})
click to toggle source
@param [Ridley::Resource] resource @param [Hash] new_attrs
# File lib/ridley/chef_object.rb, line 50 def initialize(resource, new_attrs = {}) @resource = resource mass_assign(new_attrs) end
set_chef_id(identifier)
click to toggle source
@param [#to_sym] identifier
@return [String]
# File lib/ridley/chef_object.rb, line 14 def set_chef_id(identifier) @chef_id = identifier.to_sym end
set_chef_json_class(klass)
click to toggle source
@param [String, Symbol] klass
@return [String]
# File lib/ridley/chef_object.rb, line 39 def set_chef_json_class(klass) @chef_json_class = klass attribute(:json_class, default: klass) end
set_chef_type(type)
click to toggle source
@param [#to_s] type
@return [String]
# File lib/ridley/chef_object.rb, line 26 def set_chef_type(type) @chef_type = type.to_s attribute(:chef_type, default: type) end
Public Instance Methods
<=>(other)
click to toggle source
@param [Object] other
@return [Boolean]
# File lib/ridley/chef_object.rb, line 108 def <=>(other) self.chef_id <=> other.chef_id end
==(other)
click to toggle source
# File lib/ridley/chef_object.rb, line 112 def ==(other) self.chef_id == other.chef_id end
chef_id()
click to toggle source
@return [String]
# File lib/ridley/chef_object.rb, line 97 def chef_id get_attribute(self.class.chef_id) end
eql?(other)
click to toggle source
@param [Object] other
@return [Boolean]
# File lib/ridley/chef_object.rb, line 119 def eql?(other) self.class == other.class && self == other end
hash()
click to toggle source
# File lib/ridley/chef_object.rb, line 123 def hash self.chef_id.hash end
inspect()
click to toggle source
# File lib/ridley/chef_object.rb, line 101 def inspect "#<#{self.class} chef_id:#{self.chef_id}, attributes:#{self._attributes_}>" end
reload()
click to toggle source
Reload the attributes of the instantiated resource
@return [Object]
# File lib/ridley/chef_object.rb, line 89 def reload new_attributes = resource.find(self)._attributes_ @_attributes_ = nil mass_assign(new_attributes) self end
save()
click to toggle source
Creates a resource on the target remote or updates one if the resource already exists.
@raise [Errors::InvalidResource]
if the resource does not pass validations
@return [Boolean]
# File lib/ridley/chef_object.rb, line 62 def save raise Errors::InvalidResource.new(self.errors) unless valid? mass_assign(resource.create(self)._attributes_) true rescue Errors::HTTPConflict self.update true end
update()
click to toggle source
Updates the instantiated resource on the target remote with any changes made to self
@raise [Errors::InvalidResource]
if the resource does not pass validations
@return [Boolean]
# File lib/ridley/chef_object.rb, line 79 def update raise Errors::InvalidResource.new(self.errors) unless valid? mass_assign(resource.update(self)._attributes_) true end