Class: InertiaRails::LazyProp
- Defined in:
- lib/inertia_rails/lazy_prop.rb
Instance Method Summary collapse
- #call(controller) ⇒ Object
-
#initialize(value = nil, &block) ⇒ LazyProp
constructor
A new instance of LazyProp.
- #value ⇒ Object
Constructor Details
#initialize(value = nil, &block) ⇒ LazyProp
Returns a new instance of LazyProp.
5 6 7 8 9 10 |
# File 'lib/inertia_rails/lazy_prop.rb', line 5 def initialize(value = nil, &block) raise ArgumentError, 'You must provide either a value or a block, not both' if value && block @value = value @block = block end |
Instance Method Details
#call(controller) ⇒ Object
12 13 14 |
# File 'lib/inertia_rails/lazy_prop.rb', line 12 def call(controller) value.respond_to?(:call) ? controller.instance_exec(&value) : value end |
#value ⇒ Object
16 17 18 |
# File 'lib/inertia_rails/lazy_prop.rb', line 16 def value @value.nil? ? @block : @value end |