Class: InertiaHanami::PropEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia_hanami/prop_evaluator.rb

Overview

Resolves a props structure (plain values, Procs, Props::Base wrappers, and nested hashes thereof) against a Hanami action instance, so prop blocks can access the action's params/session/deps via instance_exec.

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ PropEvaluator

Returns a new instance of PropEvaluator.



8
9
10
# File 'lib/inertia_hanami/prop_evaluator.rb', line 8

def initialize(action)
  @action = action
end

Instance Method Details

#evaluate(props) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/inertia_hanami/prop_evaluator.rb', line 12

def evaluate(props)
  case props
  when Hash
    props.transform_values { |value| evaluate(value) }
  when Props::Base
    props.with(block: resolved_block(props.block))
  when Proc
    evaluate(@action.instance_exec(&props))
  else
    props
  end
end