Class: Grape::Util::LazyValue

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/util/lazy_value.rb

Direct Known Subclasses

LazyValueEnumerable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, access_keys = []) ⇒ LazyValue

Returns a new instance of LazyValue.



5
6
7
8
# File 'lib/grape/util/lazy_value.rb', line 5

def initialize(value, access_keys = [])
  @value = value
  @access_keys = access_keys
end

Instance Attribute Details

#access_keysObject (readonly)

Returns the value of attribute access_keys.



4
5
6
# File 'lib/grape/util/lazy_value.rb', line 4

def access_keys
  @access_keys
end

Instance Method Details

#evaluateObject



15
16
17
# File 'lib/grape/util/lazy_value.rb', line 15

def evaluate
  @value
end

#evaluate_from(configuration) ⇒ Object



10
11
12
13
# File 'lib/grape/util/lazy_value.rb', line 10

def evaluate_from(configuration)
  matching_lazy_value = configuration.fetch(@access_keys)
  matching_lazy_value.evaluate
end

#lazy?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/grape/util/lazy_value.rb', line 19

def lazy?
  true
end

#reached_by(parent_access_keys, access_key) ⇒ Object



23
24
25
26
# File 'lib/grape/util/lazy_value.rb', line 23

def reached_by(parent_access_keys, access_key)
  @access_keys = parent_access_keys + [access_key]
  self
end

#to_sObject



28
29
30
# File 'lib/grape/util/lazy_value.rb', line 28

def to_s
  evaluate.to_s
end