Module: Dronejob::Modules::Phases
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveSupport::Callbacks
- Included in:
- Base
- Defined in:
- lib/dronejob/modules/phases.rb
Instance Method Summary collapse
- #completed_phase?(phase) ⇒ Boolean
- #include_helper(helper) ⇒ Object
- #log_phase ⇒ Object
- #prev_phase(phase) ⇒ Object
- #run_phases ⇒ Object
- #skip_phase?(phase, phase_config) ⇒ Boolean
Instance Method Details
#completed_phase?(phase) ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/dronejob/modules/phases.rb', line 66 def completed_phase?(phase) if self.class.stateful? @commits.include?(phase.to_s) else false end end |
#include_helper(helper) ⇒ Object
60 61 62 63 64 |
# File 'lib/dronejob/modules/phases.rb', line 60 def include_helper(helper) helper_path = "helpers/#{helper}" require "./app/#{helper_path}" self.class.send(:include, helper_path.camelcase.constantize) end |
#log_phase ⇒ Object
23 |
# File 'lib/dronejob/modules/phases.rb', line 23 def log_phase; end |
#prev_phase(phase) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/dronejob/modules/phases.rb', line 87 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 ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dronejob/modules/phases.rb', line 25 def run_phases self.class.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) ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dronejob/modules/phases.rb', line 74 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 |