Class: Grape::Util::Lazy::ValueEnumerable
- Inherits:
-
Value
- Object
- 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, #lazy?, #reached_by, #to_s
Instance Method Details
7
8
9
10
11
12
13
|
# File 'lib/grape/util/lazy/value_enumerable.rb', line 7
def [](key)
if @value_hash[key].nil?
Value.new(nil).reached_by(access_keys, key)
else
@value_hash[key].reached_by(access_keys, key)
end
end
|
#[]=(key, value) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/grape/util/lazy/value_enumerable.rb', line 21
def []=(key, value)
@value_hash[key] = case value
when Hash
ValueHash.new(value)
when Array
ValueArray.new(value)
else
Value.new(value)
end
end
|
#fetch(access_keys) ⇒ Object
15
16
17
18
19
|
# File 'lib/grape/util/lazy/value_enumerable.rb', line 15
def fetch(access_keys)
fetched_keys = access_keys.dup
value = self[fetched_keys.shift]
fetched_keys.any? ? value.fetch(fetched_keys) : value
end
|