Module: Attributes::InstanceMethods
- Included in:
- Fog::Collection, Fog::Model
- Defined in:
- lib/fog/attributes.rb
Instance Method Summary collapse
- #_dump ⇒ Object
- #attributes ⇒ Object
- #identity ⇒ Object
- #identity=(new_identity) ⇒ Object
- #merge_attributes(new_attributes = {}) ⇒ Object
- #new_record? ⇒ Boolean
- #requires(*args) ⇒ Object
Instance Method Details
#_dump ⇒ Object
36 37 38 |
# File 'lib/fog/attributes.rb', line 36 def _dump Marshal.dump(attributes) end |
#attributes ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/fog/attributes.rb', line 40 def attributes attributes = {} for attribute in self.class.attributes attributes[attribute] = send("#{attribute}") end attributes end |
#identity ⇒ Object
48 49 50 |
# File 'lib/fog/attributes.rb', line 48 def identity send(self.class.instance_variable_get('@identity')) end |
#identity=(new_identity) ⇒ Object
52 53 54 |
# File 'lib/fog/attributes.rb', line 52 def identity=(new_identity) send("#{self.class.instance_variable_get('@identity')}=", new_identity) end |
#merge_attributes(new_attributes = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fog/attributes.rb', line 56 def merge_attributes(new_attributes = {}) for key, value in new_attributes if aliased_key = self.class.aliases[key] send("#{aliased_key}=", value) else send("#{key}=", value) end end self end |
#new_record? ⇒ Boolean
67 68 69 |
# File 'lib/fog/attributes.rb', line 67 def new_record? !identity end |
#requires(*args) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fog/attributes.rb', line 71 def requires(*args) missing = [] for arg in [:connection] | args missing << arg unless send("#{arg}") end unless missing.empty? if missing.length == 1 raise(ArgumentError, "#{missing.first} is required for this operation") else raise(ArgumentError, "#{missing[0...-1].join(", ")} and #{missing[-1]} are required for this operation") end end end |