Class: Ridley::ChefObject
- Inherits:
-
Object
- Object
- Ridley::ChefObject
show all
- Includes:
- Chozo::VariaModel, Comparable
- Defined in:
- lib/ridley/chef_object.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource, new_attrs = {}) ⇒ ChefObject
49
50
51
52
|
# File 'lib/ridley/chef_object.rb', line 49
def initialize(resource, new_attrs = {})
@resource = resource
mass_assign(new_attrs)
end
|
Class Method Details
.chef_id ⇒ String?
6
7
8
|
# File 'lib/ridley/chef_object.rb', line 6
def chef_id
@chef_id
end
|
.chef_json_class ⇒ String?
31
32
33
|
# File 'lib/ridley/chef_object.rb', line 31
def chef_json_class
@chef_json_class
end
|
.chef_type ⇒ String
18
19
20
|
# File 'lib/ridley/chef_object.rb', line 18
def chef_type
@chef_type ||= self.class.name.underscore
end
|
.set_chef_id(identifier) ⇒ String
13
14
15
|
# File 'lib/ridley/chef_object.rb', line 13
def set_chef_id(identifier)
@chef_id = identifier.to_sym
end
|
.set_chef_json_class(klass) ⇒ String
38
39
40
41
|
# File 'lib/ridley/chef_object.rb', line 38
def set_chef_json_class(klass)
@chef_json_class = klass
attribute(:json_class, default: klass)
end
|
.set_chef_type(type) ⇒ String
25
26
27
28
|
# File 'lib/ridley/chef_object.rb', line 25
def set_chef_type(type)
@chef_type = type.to_s
attribute(:chef_type, default: type)
end
|
Instance Method Details
#<=>(other) ⇒ Boolean
105
106
107
|
# File 'lib/ridley/chef_object.rb', line 105
def <=>(other)
self.chef_id <=> other.chef_id
end
|
#==(other) ⇒ Object
109
110
111
|
# File 'lib/ridley/chef_object.rb', line 109
def ==(other)
self.chef_id == other.chef_id
end
|
#chef_id ⇒ String
94
95
96
|
# File 'lib/ridley/chef_object.rb', line 94
def chef_id
get_attribute(self.class.chef_id)
end
|
#eql?(other) ⇒ Boolean
116
117
118
|
# File 'lib/ridley/chef_object.rb', line 116
def eql?(other)
self.class == other.class && self == other
end
|
#hash ⇒ Object
120
121
122
|
# File 'lib/ridley/chef_object.rb', line 120
def hash
self.chef_id.hash
end
|
#inspect ⇒ Object
98
99
100
|
# File 'lib/ridley/chef_object.rb', line 98
def inspect
"#<#{self.class} chef_id:#{self.chef_id}, attributes:#{self._attributes_}>"
end
|
#reload ⇒ Object
Reload the attributes of the instantiated resource
88
89
90
91
|
# File 'lib/ridley/chef_object.rb', line 88
def reload
mass_assign(resource.find(self)._attributes_)
self
end
|
#save ⇒ Boolean
Creates a resource on the target remote or updates one if the resource already exists.
61
62
63
64
65
66
67
68
69
|
# File 'lib/ridley/chef_object.rb', line 61
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 ⇒ Boolean
Updates the instantiated resource on the target remote with any changes made to self
78
79
80
81
82
83
|
# File 'lib/ridley/chef_object.rb', line 78
def update
raise Errors::InvalidResource.new(self.errors) unless valid?
mass_assign(resource.update(self)._attributes_)
true
end
|