Class: JobWorkflow::DryRunConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/dry_run_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(evaluator: ->(_ctx) { false }) ⇒ DryRunConfig

: (?evaluator: ^(Context) -> bool) -> void



22
23
24
# File 'lib/job_workflow/dry_run_config.rb', line 22

def initialize(evaluator: ->(_ctx) { false })
  @evaluator = evaluator
end

Instance Attribute Details

#evaluatorObject (readonly)

: ^(Context) -> bool



5
6
7
# File 'lib/job_workflow/dry_run_config.rb', line 5

def evaluator
  @evaluator
end

Class Method Details

.from_primitive_value(value) ⇒ Object

: (bool | ^(Context) -> bool | nil) -> DryRunConfig



9
10
11
12
13
14
15
16
17
18
# File 'lib/job_workflow/dry_run_config.rb', line 9

def from_primitive_value(value)
  case value
  when nil then new
  when true then new(evaluator: ->(_ctx) { true })
  when false then new(evaluator: ->(_ctx) { false })
  when Proc then new(evaluator: value)
  else
    raise ArgumentError, "dry_run must be true, false, or Proc"
  end
end

Instance Method Details

#evaluate(context) ⇒ Object

: (Context) -> bool



27
28
29
# File 'lib/job_workflow/dry_run_config.rb', line 27

def evaluate(context)
  @evaluator.call(context)
end