Class: Rudder::DSL::Job

Inherits:
Component show all
Defined in:
lib/rudder/dsl/job.rb

Overview

Concourse job

Defines a plan of work that may share state in an explicit manner.

DSL Usage:

Job are defined by a name and a plan of work.

Examples:

# Name's are set during initializtion, and may not be nil
job :awesome_job # => job.name = :awesome_job

job nil # => Raises ArgumentError
# The plan is set after construction
job :awesome_job do
  plan << { get: :some_resource   }
  plan << { get: :another_resource }
end # => plan.source = [{get: :some_resource}, {get: :another_resource}]

Instance Method Summary collapse

Methods inherited from Component

#method_missing, #respond_to?, #respond_to_missing?

Methods included from Util

#_convert_h_val, #_deep_to_h

Constructor Details

#initialize(name) ⇒ Job

All Jobs require:

  • A name

  • A plan of work

Plans are defined after initialization

Parameters:

  • name (String, Symbol)

    name of this Concourse job. Must not be nil

Raises:

  • (ArgumentError)

    when name is nil



42
43
44
45
46
# File 'lib/rudder/dsl/job.rb', line 42

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

  @job = { name: name, plan: [] }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rudder::DSL::Component

Instance Method Details

#_inner_hashObject



48
49
50
# File 'lib/rudder/dsl/job.rb', line 48

def _inner_hash
  @job
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 plan is empty



57
58
59
60
61
62
# File 'lib/rudder/dsl/job.rb', line 57

def to_h
  raise 'Name must be set for Concourse Jobs' if @job[:name].nil?
  raise 'Plan must be set for Concourse Jobs' if @job[:plan].empty?

  super.to_h
end