Class: GCI::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/gci/pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Pipeline

Returns a new instance of Pipeline.

Yields:

  • (_self)

Yield Parameters:

  • _self (GCI::Pipeline)

    the object that the method was called on



9
10
11
12
13
14
15
# File 'lib/gci/pipeline.rb', line 9

def initialize
  @jobs = Job::Collection.new
  @stages = i[build test deploy]
  @gitlab_ci_file = 'child.gitlab-ci.yml'

  yield(self) if block_given?
end

Instance Attribute Details

#gitlab_ci_file=(value) ⇒ Object (writeonly)

Sets the attribute gitlab_ci_file

Parameters:

  • value

    the value to set the attribute gitlab_ci_file to.



7
8
9
# File 'lib/gci/pipeline.rb', line 7

def gitlab_ci_file=(value)
  @gitlab_ci_file = value
end

#imageObject

Returns the value of attribute image.



6
7
8
# File 'lib/gci/pipeline.rb', line 6

def image
  @image
end

#jobsObject (readonly)

Returns the value of attribute jobs.



5
6
7
# File 'lib/gci/pipeline.rb', line 5

def jobs
  @jobs
end

#stagesObject

Returns the value of attribute stages.



6
7
8
# File 'lib/gci/pipeline.rb', line 6

def stages
  @stages
end

#variablesObject

Returns the value of attribute variables.



6
7
8
# File 'lib/gci/pipeline.rb', line 6

def variables
  @variables
end

#workflowObject

Returns the value of attribute workflow.



6
7
8
# File 'lib/gci/pipeline.rb', line 6

def workflow
  @workflow
end

Instance Method Details

#to_hObject



23
24
25
26
27
28
29
30
# File 'lib/gci/pipeline.rb', line 23

def to_h
  data = {}
  data.merge!(stages: stages.map(&:to_s))
  data.merge!(image: @image) if @image.present?
  data.merge!(workflow: @workflow) if @workflow.present?
  data.merge!(@jobs.to_h)
  data
end

#to_yamlObject



32
33
34
# File 'lib/gci/pipeline.rb', line 32

def to_yaml
  to_h.to_yaml
end

#writeObject



17
18
19
20
21
# File 'lib/gci/pipeline.rb', line 17

def write
  File.open(@gitlab_ci_file, 'wb') do |file|
    file.write(to_yaml)
  end
end