Class: InertiaRails::LazyProp
- Inherits:
-
IgnoreOnFirstLoadProp
- Object
- BaseProp
- IgnoreOnFirstLoadProp
- 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 11 12 13 14 |
# 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 InertiaRails.deprecator.warn( '`lazy` is deprecated and will be removed in InertiaRails 4.0, use `optional` instead.' ) @value = value @block = block end |
Instance Method Details
#call(controller) ⇒ Object
16 17 18 |
# File 'lib/inertia_rails/lazy_prop.rb', line 16 def call(controller) value.respond_to?(:call) ? controller.instance_exec(&value) : value end |
#value ⇒ Object
20 21 22 |
# File 'lib/inertia_rails/lazy_prop.rb', line 20 def value @value.nil? ? @block : @value end |