Class: Trailblazer::Operation::Policy::Eval

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/operation/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/operation/policy.rb', line 6

def initialize(name:nil, path:nil)
  @name = name
  @path = path
end

Instance Method Details

#call(input, options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/trailblazer/operation/policy.rb', line 11

def call(input, options)
  condition = options[@path] # this allows dependency injection.
  result    = condition.(input, options)

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

  # flow control
  result.success? # since we & this, it's only executed OnRight and the return boolean decides the direction, input is passed straight through.
end