Class: ITGlue::Asset::Attributes
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- ITGlue::Asset::Attributes
- Defined in:
- lib/itglue/asset/base/attributes.rb
Instance Method Summary collapse
- #assign_attribute(key, value) ⇒ Object
- #attributes_hash ⇒ Object
- #changes ⇒ Object
-
#initialize(*args) ⇒ Attributes
constructor
A new instance of Attributes.
- #inspect_field(field) ⇒ Object
- #keys ⇒ Object
- #remove_attribute(key) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Attributes
Returns a new instance of Attributes.
4 5 6 7 |
# File 'lib/itglue/asset/base/attributes.rb', line 4 def initialize(*args) @changed_attribute_keys = [] super end |
Instance Method Details
#assign_attribute(key, value) ⇒ Object
9 10 11 12 |
# File 'lib/itglue/asset/base/attributes.rb', line 9 def assign_attribute(key, value) @changed_attribute_keys << key.to_sym self[key] = value end |
#attributes_hash ⇒ Object
23 24 25 |
# File 'lib/itglue/asset/base/attributes.rb', line 23 def attributes_hash self.to_h end |
#changes ⇒ Object
36 37 38 39 40 41 |
# File 'lib/itglue/asset/base/attributes.rb', line 36 def changes attributes_hash = self.attributes_hash @changed_attribute_keys.each_with_object({}) do |key, changes| changes[key] = attributes_hash[key] end end |
#inspect_field(field) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/itglue/asset/base/attributes.rb', line 27 def inspect_field(field) value = self[field] if value.is_a?(String) value.length > 100 ? "\"#{value[0..100]}...\"" : "\"#{value}\"" else value.inspect end end |
#keys ⇒ Object
19 20 21 |
# File 'lib/itglue/asset/base/attributes.rb', line 19 def keys self.to_h.keys end |
#remove_attribute(key) ⇒ Object
14 15 16 17 |
# File 'lib/itglue/asset/base/attributes.rb', line 14 def remove_attribute(key) @changed_attribute_keys.delete(key) self.delete_field(key) end |