Class: Fuik::DotAccess::AccessPayload
- Inherits:
-
Object
- Object
- Fuik::DotAccess::AccessPayload
show all
- Defined in:
- lib/fuik/dot_access.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AccessPayload.
10
11
12
|
# File 'lib/fuik/dot_access.rb', line 10
def initialize(payload)
@payload = payload
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/fuik/dot_access.rb', line 34
def method_missing(method_name, *arguments)
return super unless arguments.empty? && !block_given?
value = @payload[method_name] || @payload[method_name.to_s] || @payload[method_name.to_sym]
value.is_a?(Hash) ? self.class.new(value) : value
end
|
Instance Method Details
#[](key) ⇒ Object
14
15
16
17
18
|
# File 'lib/fuik/dot_access.rb', line 14
def [](key)
value = @payload[key] || @payload[key.to_s] || @payload[key.to_sym]
value.is_a?(Hash) ? self.class.new(value) : value
end
|
#[]=(key, value) ⇒ Object
20
21
22
|
# File 'lib/fuik/dot_access.rb', line 20
def []=(key, value)
@payload[key] = value
end
|
#dig(*keys) ⇒ Object
24
25
26
27
28
|
# File 'lib/fuik/dot_access.rb', line 24
def dig(*keys)
value = @payload.dig(*keys)
value.is_a?(Hash) ? self.class.new(value) : value
end
|
#key?(key) ⇒ Boolean
30
31
32
|
# File 'lib/fuik/dot_access.rb', line 30
def key?(key)
@payload.key?(key) || @payload.key?(key.to_s) || @payload.key?(key.to_sym)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
41
42
43
|
# File 'lib/fuik/dot_access.rb', line 41
def respond_to_missing?(method_name, include_private = false)
key?(method_name) || super
end
|
#to_h ⇒ Object
45
|
# File 'lib/fuik/dot_access.rb', line 45
def to_h = @payload
|