Module: OscMacheteRails::Workflow::StatusMethods

Defined in:
lib/osc_machete_rails/workflow.rb

Overview

depends on jobs_active_record_relation being defined

Instance Method Summary collapse

Instance Method Details

#statusOSC::Machete::Status

Reduce the jobs to a single OSC::Machete:Status value

Assumes ‘jobs_active_record_relation` is a Statusable ActiveRecord model. Get array of status values (one for each job) and then add them together to get one value. OSC::Machete::Status#+ is overridden to return the highest precendent status value when adding two together.

FIXME: it might be clearer in code to use ‘max` instead of `+` i.e. statuses.reduce(&:max) and rename OSC::Machete::Status#+.

Returns:

  • (OSC::Machete::Status)

    a single value representing the status



240
241
242
243
# File 'lib/osc_machete_rails/workflow.rb', line 240

def status
  statuses = jobs_active_record_relation.to_a.map(&:status)
  statuses.empty? ? OSC::Machete::Status. : statuses.reduce(&:+)
end