Class: Pipedawg::Pipeline
- Inherits:
-
Object
- Object
- Pipedawg::Pipeline
- Defined in:
- lib/pipedawg/pipeline.rb
Overview
pipeline class
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(name = 'pipeline', opts = {}) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #to_yaml ⇒ Object
- #to_yaml_file(file = 'pipeline.yml') ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(name = 'pipeline', opts = {}) ⇒ Pipeline
Returns a new instance of Pipeline.
8 9 10 11 12 13 14 15 16 |
# File 'lib/pipedawg/pipeline.rb', line 8 def initialize(name = 'pipeline', opts = {}) @name = name @opts = { jobs: [Pipedawg::Job.new], stages: ['build'], workflow: nil }.merge(opts) update end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/pipedawg/pipeline.rb', line 6 def name @name end |
#opts ⇒ Object
Returns the value of attribute opts.
6 7 8 |
# File 'lib/pipedawg/pipeline.rb', line 6 def opts @opts end |
Instance Method Details
#to_yaml ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/pipedawg/pipeline.rb', line 18 def to_yaml require 'json' require 'yaml' pipeline = opts.compact.reject { |k, _| %i[jobs].include? k } opts[:jobs].each do |job| pipeline.merge!(job.to_hash) end JSON.parse(pipeline.to_json).to_yaml end |
#to_yaml_file(file = 'pipeline.yml') ⇒ Object
28 29 30 |
# File 'lib/pipedawg/pipeline.rb', line 28 def to_yaml_file(file = 'pipeline.yml') File.write(file, to_yaml) end |
#update ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/pipedawg/pipeline.rb', line 32 def update stages = [] opts[:jobs].each do |job| stage = stage_from_needs(opts[:jobs], job.name) stages << stage job.opts[:stage] = stage.to_s end opts[:stages] = stages.uniq.sort.map(&:to_s) end |