Class: Searchkick::HashWrapper
- Inherits:
-
Object
- Object
- Searchkick::HashWrapper
show all
- Defined in:
- lib/searchkick/hash_wrapper.rb
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ HashWrapper
Returns a new instance of HashWrapper.
3
4
5
|
# File 'lib/searchkick/hash_wrapper.rb', line 3
def initialize(attributes)
@attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/searchkick/hash_wrapper.rb', line 23
def method_missing(name, ...)
if @attributes.key?(name.to_s)
self[name]
else
super
end
end
|
Instance Method Details
#[](name) ⇒ Object
7
8
9
|
# File 'lib/searchkick/hash_wrapper.rb', line 7
def [](name)
@attributes[name.to_s]
end
|
#as_json ⇒ Object
15
16
17
|
# File 'lib/searchkick/hash_wrapper.rb', line 15
def as_json(...)
@attributes.as_json(...)
end
|
#inspect ⇒ Object
35
36
37
38
39
|
# File 'lib/searchkick/hash_wrapper.rb', line 35
def inspect
attributes = @attributes.reject { |k, v| k[0] == "_" }.map { |k, v| "#{k}: #{v.inspect}" }
attributes.unshift(attributes.pop) "#<#{self.class.name} #{attributes.join(", ")}>"
end
|
#respond_to_missing?(name) ⇒ Boolean
31
32
33
|
# File 'lib/searchkick/hash_wrapper.rb', line 31
def respond_to_missing?(name, ...)
@attributes.key?(name.to_s) || super
end
|
#to_h ⇒ Object
11
12
13
|
# File 'lib/searchkick/hash_wrapper.rb', line 11
def to_h
@attributes
end
|
#to_json ⇒ Object
19
20
21
|
# File 'lib/searchkick/hash_wrapper.rb', line 19
def to_json(...)
@attributes.to_json(...)
end
|