module Dronejob::Modules::Phases
Public Instance Methods
completed_phase?(phase)
click to toggle source
# File lib/dronejob/modules/phases.rb, line 73 def completed_phase?(phase) if self.class.stateful? @commits.include?(phase.to_s) else false end end
include_helper(helper)
click to toggle source
# File lib/dronejob/modules/phases.rb, line 67 def include_helper(helper) helper_path = "helpers/#{helper}" require "./app/#{helper_path}" self.class.send(:include, helper_path.camelcase.constantize) end
log_phase()
click to toggle source
# File lib/dronejob/modules/phases.rb, line 24 def log_phase; end
phase(key, options)
click to toggle source
# File lib/dronejob/modules/phases.rb, line 14 def phase(key, options) @phases ||= {} @phases[key] = options end
phases()
click to toggle source
# File lib/dronejob/modules/phases.rb, line 19 def phases @phases end
prev_phase(phase)
click to toggle source
# File lib/dronejob/modules/phases.rb, line 94 def prev_phase(phase) phases = self.class.phases.keys index = phases.index(phase.to_sym) return nil if index.nil? return "start" if index == 0 phases[index - 1] end
run_phases()
click to toggle source
# File lib/dronejob/modules/phases.rb, line 26 def run_phases if self.respond_to?(:before) phases = before(self.class.phases) else phases = self.class.phases end phases.each do |phase, phase_config| @phase = phase @phase_config = phase_config # initialize phase fail "Phase not found: '#{phase}'" unless self.respond_to?(phase) run_callbacks :phase do if completed_phase?(phase) and !@phase_config[:always_run] info("already completed") elsif skip_phase?(phase, phase_config) info("skipping...") else info("running phase #{phase}") # Require libraries @phase_config[:require]&.each do |library| require library end # Include helpers @phase_config[:helpers]&.each do |helper| include_helper(helper) end # OLD CODE FROM CORE public_send(phase) end end end @phase = "complete" @dronejob_completed = true git_commit("dronejob_completed") if self.class.stateful? end
skip_phase?(phase, phase_config)
click to toggle source
# File lib/dronejob/modules/phases.rb, line 81 def skip_phase?(phase, phase_config) if phase_config[:if] if phase_config[:if].class == String or phase_config[:if].class == Symbol return true unless param(phase_config[:if]) elsif phase_config[:if].class == Array return true unless phase_config[:if].all? { |p| param(p) == true } elsif phase_config[:if].class == Proc return true unless instance_eval(&phase_config[:if]) end end param(:skip)&.include?(phase.to_s) end