Class: CanvasSync::JobChain
- Inherits:
-
Object
- Object
- CanvasSync::JobChain
- Defined in:
- lib/canvas_sync/job_chain.rb
Constant Summary collapse
- VALID_PLACEMENT_PARAMETERS =
%i[before after].freeze
Instance Attribute Summary collapse
-
#chain_data ⇒ Object
readonly
Returns the value of attribute chain_data.
Instance Method Summary collapse
- #global_options ⇒ Object
-
#initialize(chain_data) ⇒ JobChain
constructor
A new instance of JobChain.
- #insert(new_job, **kwargs) ⇒ Object
- #jobs ⇒ Object
- #merge_options(job, options) ⇒ Object
- #process!(extra_options: {}) ⇒ Object
Constructor Details
#initialize(chain_data) ⇒ JobChain
Returns a new instance of JobChain.
9 10 11 |
# File 'lib/canvas_sync/job_chain.rb', line 9 def initialize(chain_data) @chain_data = chain_data end |
Instance Attribute Details
#chain_data ⇒ Object (readonly)
Returns the value of attribute chain_data.
3 4 5 |
# File 'lib/canvas_sync/job_chain.rb', line 3 def chain_data @chain_data end |
Instance Method Details
#global_options ⇒ Object
17 18 19 |
# File 'lib/canvas_sync/job_chain.rb', line 17 def chain_data[:global_options] end |
#insert(new_job, **kwargs) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/canvas_sync/job_chain.rb', line 27 def insert(new_job, **kwargs) invalid_params = kwargs.keys - VALID_PLACEMENT_PARAMETERS raise "Invalid placement parameters: #{invalid_params.map(&:to_s).join(', ')}" if invalid_params.present? raise "Exactly one placement parameter may be provided" if kwargs.values.compact!.length > 1 if !kwargs.present? jobs << new_job else placement = kwargs.keys[0] relative_to = kwargs.values[0] index = jobs.index { |job| job_matches_pattern(job, relative_to) } raise "Could not find a \"#{relative_to}\" job in the chain" if index.nil? index += 1 if placement == :after new_job[:job] = new_job[:job].to_s jobs.insert(index, new_job) end end |
#jobs ⇒ Object
13 14 15 |
# File 'lib/canvas_sync/job_chain.rb', line 13 def jobs chain_data[:jobs] end |
#merge_options(job, options) ⇒ Object
21 22 23 24 25 |
# File 'lib/canvas_sync/job_chain.rb', line 21 def (job, ) jobs.each do |j| j[:options].deep_merge!() if job_matches_pattern(j, job) end end |
#process!(extra_options: {}) ⇒ Object
47 48 49 |
# File 'lib/canvas_sync/job_chain.rb', line 47 def process!(extra_options: {}) CanvasSync::invoke_next(self, extra_options: ) end |