Module: Chewy::Type::Wrapper
Instance Attribute Summary collapse
-
#_data ⇒ Object
Returns the value of attribute _data.
-
#_object ⇒ Object
Returns the value of attribute _object.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method, _) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/chewy/type/wrapper.rb', line 22 def method_missing(method, *args, &block) if @attributes.key?(method.to_s) @attributes[method.to_s] else nil end end |
Instance Attribute Details
#_data ⇒ Object
Returns the value of attribute _data.
6 7 8 |
# File 'lib/chewy/type/wrapper.rb', line 6 def _data @_data end |
#_object ⇒ Object
Returns the value of attribute _object.
6 7 8 |
# File 'lib/chewy/type/wrapper.rb', line 6 def _object @_object end |
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/chewy/type/wrapper.rb', line 6 def attributes @attributes end |
Instance Method Details
#==(other) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/chewy/type/wrapper.rb', line 12 def ==(other) if other.is_a?(Chewy::Type) self.class == other.class && (respond_to?(:id) ? id == other.id : attributes == other.attributes) elsif other.respond_to?(:id) id.to_s == other.id.to_s else false end end |
#initialize(attributes = {}) ⇒ Object
8 9 10 |
# File 'lib/chewy/type/wrapper.rb', line 8 def initialize(attributes = {}) @attributes = attributes.stringify_keys end |
#respond_to_missing?(method, _) ⇒ Boolean
30 31 32 |
# File 'lib/chewy/type/wrapper.rb', line 30 def respond_to_missing?(method, _) @attributes.key?(method.to_s) || super end |