Class: Trailblazer::Macro::Policy::Eval
- Inherits:
-
Object
- Object
- Trailblazer::Macro::Policy::Eval
- Defined in:
- lib/trailblazer/macro/policy.rb
Overview
Step: This generically ‘call`s a policy and then pushes its result to `options`. You can use any callable object as a policy with this step.
Instance Method Summary collapse
-
#call(ctx, flow_options, **circuit_options) ⇒ Object
incoming low-level interface.
-
#initialize(name: nil, path: nil) ⇒ Eval
constructor
A new instance of Eval.
Constructor Details
#initialize(name: nil, path: nil) ⇒ Eval
Returns a new instance of Eval.
6 7 8 9 |
# File 'lib/trailblazer/macro/policy.rb', line 6 def initialize(name: nil, path: nil) @name = name @path = path end |
Instance Method Details
#call(ctx, flow_options, **circuit_options) ⇒ Object
incoming low-level interface. outgoing Task::Binary API.
Retrieve the injectable condition, execute it and interpret its Result object.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trailblazer/macro/policy.rb', line 15 def call((ctx, ), **) condition = ctx[@path] # this allows dependency injection. result = condition.([ctx, ], **) ctx[:"policy.#{@name}"] = result[:policy] # assign the policy as a ctx variable. ctx[:"result.policy.#{@name}"] = result # flow control signal = result.success? ? Trailblazer::Activity::Right : Trailblazer::Activity::Left return signal, [ctx, ] end |