class Rudder::DSL::Resource

Concourse Resource, defines inputs and outputs of a Concourse Job

DSL Usage:

{Rudder::DSL::Resource} are defined by a name, type, and source.

@example

# Name's are set during initialization, and may not be nil.
resource :awesome_resource # => resource.name = :awesome_resource

resource nil # => Raises ArgumentError

@example

# Type's are typically set during initialization
resource :awesome_resource, :git # => resource.type = :git

# but it may be set in the +resource+ block
resource :awesome_resource do
  type :git
end # => resource.type = :git
# this is useful when definining +Resources+ to be included in multiple pipelines,
# where the type does not change but the name may

@example

# Source is set after construction
resource :awesome_resource, :git do
  source[:uri]    = 'https://github.com/jhmcstanton/rudder.git'
  source[:branch] = 'master'
end

Public Class Methods

new(name, type = nil) click to toggle source

All resources require:

  • Name of the resource. Must be unique across resources (not enforcable here).

  • The concourse resource type. Not verified until rendered to a Hash.

@param name [String, Symbol] name of this Concourse resource. Must not be nil. @param type [String, Symbol] of this Concoure Resource.

May be nil here, must be set at compile time.
Calls superclass method
# File lib/rudder/dsl/resource.rb, line 49
def initialize(name, type = nil)
  raise super.ArgumentError 'Name cannot be nil' if name.nil?

  @resource = { name: name, type: type, source: {} }
end

Public Instance Methods

_inner_hash() click to toggle source
# File lib/rudder/dsl/resource.rb, line 77
def _inner_hash
  @resource
end
sub_path(child_path) click to toggle source

@return [String] the child_path prefixed by this resource's name

Useful for creating the full path to a file in a Resource without knowing it's underlying concourse name.

# File lib/rudder/dsl/resource.rb, line 61
def sub_path(child_path)
  File.join(@resource[:name].to_s, child_path)
end
to_h() click to toggle source

@return [Hash] YAML friendly Hash representation of this resource

@raise [RuntimeError] if type is nil or source is empty

Calls superclass method Rudder::DSL::Component#to_h
# File lib/rudder/dsl/resource.rb, line 70
def to_h
  raise 'Type must be set for Concourse Resources'   if @resource[:type].nil?
  raise 'Source must be set for Concourse Resources' if @resource[:source].empty?

  super.to_h
end