Class: Trailblazer::Macro::Policy::Eval

Inherits:
Object
  • Object
show all
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

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, flow_options), **circuit_options)
  condition = ctx[@path] # this allows dependency injection.
  result    = condition.([ctx, flow_options], **circuit_options)

  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, flow_options]
end