Class: Grape::Util::LazyValueEnumerable
Instance Attribute Summary
Attributes inherited from LazyValue
#access_keys
Instance Method Summary
collapse
Methods inherited from LazyValue
#evaluate, #evaluate_from, #initialize, #lazy?, #reached_by, #to_s
Instance Method Details
#[](key) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/grape/util/lazy_value.rb', line 36
def [](key)
if @value_hash[key].nil?
LazyValue.new(nil).reached_by(access_keys, key)
else
@value_hash[key].reached_by(access_keys, key)
end
end
|
#[]=(key, value) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/grape/util/lazy_value.rb', line 50
def []=(key, value)
@value_hash[key] = if value.is_a?(Hash)
LazyValueHash.new(value)
elsif value.is_a?(Array)
LazyValueArray.new(value)
else
LazyValue.new(value)
end
end
|
#fetch(access_keys) ⇒ Object
44
45
46
47
48
|
# File 'lib/grape/util/lazy_value.rb', line 44
def fetch(access_keys)
fetched_keys = access_keys.dup
value = self[fetched_keys.shift]
fetched_keys.any? ? value.fetch(fetched_keys) : value
end
|