Class: Snoot::Run

Inherits:
Data
  • Object
show all
Defined in:
lib/snoot/run.rb

Overview

One analysis pass: the input paths, the outcome (pending, finding_rendered, nothing_to_report, analysis_failed), and the selected_finding when one was chosen. Enforces the transition rules and the presence invariants – selected_finding iff finding_rendered, failure iff analysis_failed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths:, outcome:, selected_finding: nil, failure: nil) ⇒ Run

Returns a new instance of Run.



10
11
12
13
14
# File 'lib/snoot/run.rb', line 10

def initialize(paths:, outcome:, selected_finding: nil, failure: nil)
  super
  enforce_field_when!(:selected_finding, outcome: :finding_rendered)
  enforce_field_when!(:failure, outcome: :analysis_failed)
end

Instance Attribute Details

#failureObject (readonly)

Returns the value of attribute failure

Returns:

  • (Object)

    the current value of failure



9
10
11
# File 'lib/snoot/run.rb', line 9

def failure
  @failure
end

#outcomeObject (readonly)

Returns the value of attribute outcome

Returns:

  • (Object)

    the current value of outcome



9
10
11
# File 'lib/snoot/run.rb', line 9

def outcome
  @outcome
end

#pathsObject (readonly)

Returns the value of attribute paths

Returns:

  • (Object)

    the current value of paths



9
10
11
# File 'lib/snoot/run.rb', line 9

def paths
  @paths
end

#selected_findingObject (readonly)

Returns the value of attribute selected_finding

Returns:

  • (Object)

    the current value of selected_finding



9
10
11
# File 'lib/snoot/run.rb', line 9

def selected_finding
  @selected_finding
end

Instance Method Details

#transition_to(target, selected_finding: nil, failure: nil) ⇒ Object

Raises:



16
17
18
19
20
# File 'lib/snoot/run.rb', line 16

def transition_to(target, selected_finding: nil, failure: nil)
  raise StateError, "transition #{outcome} -> #{target} is not declared" unless outcome == :pending

  with(outcome: target, selected_finding: selected_finding, failure: failure)
end