Class: Rudder::DSL::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/rudder/dsl/group.rb

Overview

Concourse group. Logically groups together Concourse jobs in the UI.

DSL Usage:

Group's are the simplest element of any Concourse Pipeline, defined by only a name and a non-empty list of jobs.

Examples:

# Name's are typically set during initialization
group :my_awesome_group do # => Name is set to :my_awesome_group

# but the name may be changed post construction as well
group :not_the_best_name do # => Name initialized to :not_the_best_name
  name :the_best_name
end # => but is set to :the_best_name after the block is executed
# Job's are always set post construction. They can be added
# individually:
group :my_awesome_group do
  job :some_prereq
  job :my_awesome_work
end # => group.jobs = [:some_prereq, :my_awesome_work]

# and they can be added in collections
group :my_awesome_group do
  jobs :a_job, :and_another, :and_one_more
end # => group.jobs = [:a_job, :and_another, :and_one_more]

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Group

All Rudder::DSL::Group's require

  • Name of the group

  • A list of jobs in the group

Jobs are added after initilization.

Parameters:

  • the (String, Symbol)

    non-nil name of this group

Raises:

  • (ArgumentError)

    if name is +nil



53
54
55
56
57
58
# File 'lib/rudder/dsl/group.rb', line 53

def initialize(name)
  raise super.ArgumentError 'Name cannot be nil' if name.nil?

  @name = name
  @jobs = Set.new
end

Instance Method Details

#job(job_name) ⇒ Set<String, Symbol>

Add a single job to the jobs list

Parameters:

  • job_name (String, Symbol)

    to add to the jobs list

Returns:

  • (Set<String, Symbol>)

    the latest list of jobs



78
79
80
# File 'lib/rudder/dsl/group.rb', line 78

def job(job_name)
  jobs job_name
end

#jobs(*args) ⇒ Set<String, Symbol>

Adds all the jobs to the jobs list

Parameters:

Returns:

  • (Set<String, Symbol>)

    the latest list of jobs



89
90
91
92
# File 'lib/rudder/dsl/group.rb', line 89

def jobs(*args)
  args.each { |arg| @jobs << arg }
  @jobs
end

#name(name = nil) ⇒ String, Symbol

Replace's this Rudder::DSL::Group's name unless name is nil.

Parameters:

  • name (String, Symbol) (defaults to: nil)

    the new name to use. Ignored if nil.

Returns:

  • (String, Symbol)

    the latest component name.



67
68
69
70
# File 'lib/rudder/dsl/group.rb', line 67

def name(name = nil)
  @name = name unless name.nil?
  @name
end

#to_hHash

Returns YAML friendly Hash representation of this resource

Returns:

  • (Hash)

    YAML friendly Hash representation of this resource

Raises:

  • (RuntimeError)

    if name is nil or jobs is empty



99
100
101
102
103
104
105
106
107
# File 'lib/rudder/dsl/group.rb', line 99

def to_h
  raise 'Groups require a name'         if @name.nil?
  raise 'Groups require at least 1 job' if @jobs.empty?

  {
    'name' => @name.to_s,
    'jobs' => @jobs.to_a.map(&:to_s)
  }
end