Class: Resteze::Object
- Inherits:
-
Hashie::Trash
- Object
- Hashie::Trash
- Resteze::Object
- Includes:
- Hashie::Extensions::DeepMerge, ApiModule
- Defined in:
- lib/resteze/object.rb
Instance Attribute Summary collapse
-
#property_bag ⇒ Object
readonly
Returns the value of attribute property_bag.
-
#resteze_metadata ⇒ Object
readonly
Returns the value of attribute resteze_metadata.
Class Method Summary collapse
Instance Method Summary collapse
-
#[]=(property, value) ⇒ Object
This allows us to take advantage of the #property features of the Hashie::Dash, but also to support unexpected hash values and store them in the metadata property.
-
#initialize(attributes = {}) ⇒ Object
constructor
A new instance of Object.
-
#initialize_from(values) ⇒ Object
This is replaced with the idea of Hashie in Channel Advisor.
- #merge_from(values) ⇒ Object
- #persisted? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Object
Returns a new instance of Object.
8 9 10 11 12 13 |
# File 'lib/resteze/object.rb', line 8 def initialize(attributes = {}, &) = {} @property_bag = {} super end |
Instance Attribute Details
#property_bag ⇒ Object (readonly)
Returns the value of attribute property_bag.
6 7 8 |
# File 'lib/resteze/object.rb', line 6 def property_bag @property_bag end |
#resteze_metadata ⇒ Object (readonly)
Returns the value of attribute resteze_metadata.
6 7 8 |
# File 'lib/resteze/object.rb', line 6 def end |
Class Method Details
.class_name ⇒ Object
24 25 26 |
# File 'lib/resteze/object.rb', line 24 def self.class_name name.demodulize end |
.construct_from(payload) ⇒ Object
32 33 34 |
# File 'lib/resteze/object.rb', line 32 def self.construct_from(payload) new.initialize_from(payload) end |
.object_key ⇒ Object
28 29 30 |
# File 'lib/resteze/object.rb', line 28 def self.object_key api_module.default_object_key(self) end |
Instance Method Details
#[]=(property, value) ⇒ Object
This allows us to take advantage of the #property features of the Hashie::Dash, but also to support unexpected hash values and store them in the metadata property
18 19 20 21 22 |
# File 'lib/resteze/object.rb', line 18 def []=(property, value) super rescue NoMethodError @property_bag = property_bag.merge({ property => value }) end |
#initialize_from(values) ⇒ Object
This is replaced with the idea of Hashie in Channel Advisor
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/resteze/object.rb', line 37 def initialize_from(values) values = values.deep_symbolize_keys if self.class.object_key update_attributes(values[self.class.object_key] || {}) else update_attributes(values) end (values) self end |
#merge_from(values) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/resteze/object.rb', line 48 def merge_from(values) values = values.deep_symbolize_keys if self.class.object_key data = values[self.class.object_key] || {} = values.except(self.class.object_key) || {} else data = values = {} end deep_merge!(data) .deep_merge!() self end |
#persisted? ⇒ Boolean
63 64 65 |
# File 'lib/resteze/object.rb', line 63 def persisted? respond_to?(:id) && id.present? end |