Class: Grape::Util::Lazy::ValueEnumerable
- Inherits:
-
Value
- Object
- Base
- Value
- Grape::Util::Lazy::ValueEnumerable
show all
- Defined in:
- lib/grape/util/lazy/value_enumerable.rb
Instance Attribute Summary
Attributes inherited from Value
#access_keys
Instance Method Summary
collapse
Methods inherited from Value
#evaluate, #evaluate_from, #initialize, #reached_by
Methods inherited from Base
#to_s
Instance Method Details
#[](key) ⇒ Object
7
8
9
10
11
|
# File 'lib/grape/util/lazy/value_enumerable.rb', line 7
def [](key)
return Value.new(nil).reached_by(access_keys, key) if @value_hash[key].nil?
@value_hash[key].reached_by(access_keys, key)
end
|
#[]=(key, value) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/grape/util/lazy/value_enumerable.rb', line 17
def []=(key, value)
value_class = case value
when Hash
ValueHash
when Array
ValueArray
else
Value
end
@value_hash[key] = value_class.new(value)
end
|
#fetch(access_keys) ⇒ Object
13
14
15
|
# File 'lib/grape/util/lazy/value_enumerable.rb', line 13
def fetch(access_keys)
access_keys.reduce(self) { |node, key| node[key] }
end
|