class Trailblazer::Macro::Policy::Eval

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.

Public Class Methods

new(name: nil, path: nil) click to toggle source
# File lib/trailblazer/macro/policy.rb, line 6
def initialize(name: nil, path: nil)
  @name = name
  @path = path
end

Public Instance Methods

call((options, flow_options), **circuit_options) click to toggle source

incoming low-level {Task API}. outgoing Task::Binary API.

# File lib/trailblazer/macro/policy.rb, line 13
def call((options, flow_options), **circuit_options)
  condition = options[@path] # this allows dependency injection.
  result    = condition.([options, flow_options], **circuit_options)

  options[:"policy.#{@name}"]        = result[:policy] # assign the policy as a skill.
  options[:"result.policy.#{@name}"] = result

  # flow control
  signal = result.success? ? Trailblazer::Activity::Right : Trailblazer::Activity::Left # since we & this, it's only executed OnRight and the return boolean decides the direction, input is passed straight through.

  return signal, [options, flow_options]
end