Module: Chewy::Type::Wrapper

Extended by:
ActiveSupport::Concern
Included in:
Chewy::Type
Defined in:
lib/chewy/type/wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#_dataObject

Returns the value of attribute _data.



6
7
8
# File 'lib/chewy/type/wrapper.rb', line 6

def _data
  @_data
end

#_objectObject

Returns the value of attribute _object.



6
7
8
# File 'lib/chewy/type/wrapper.rb', line 6

def _object
  @_object
end

#attributesObject

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/chewy/type/wrapper.rb', line 30

def respond_to_missing?(method, _)
  @attributes.key?(method.to_s) || super
end