Sha256: 9a5b0a3318f4bf0ba5beec2d40d1163019739a6b0ed83a727b54585d77e82c7e

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require_relative 'component'

module Rudder
  module DSL
    ##
    # Concourse job
    #
    # Defines a plan of work that may share state
    # in an explicit manner.
    #
    # == DSL Usage:
    #
    # {Rudder::DSL::Job} are defined by a +name+ and a +plan+ of work.
    #
    # @example
    #   # Name's are set during initializtion, and may not be nil
    #   job :awesome_job # => job.name = :awesome_job
    #
    #   job nil # => Raises ArgumentError
    #
    # @example
    #   # 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}]
    #
    class Job < Rudder::DSL::Component
      ##
      # All Jobs require:
      #
      # - A name
      # - A plan of work
      #
      # Plans are defined after initialization
      #
      # @param name [String, Symbol] name of this Concourse job. Must not be +nil+
      # @raise [ArgumentError] when +name+ is nil
      #
      def initialize(name)
        raise super.ArgumentError 'Name cannot be nil' if name.nil?

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

      def _inner_hash
        @job
      end

      ##
      # @return [Hash] YAML friendly +Hash+ representation of this resource
      #
      # @raise [RuntimeError] if +name+ is +nil+ or +plan+ is empty
      #
      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rudder-0.3.1 lib/rudder/dsl/job.rb
rudder-0.3.0 lib/rudder/dsl/job.rb
rudder-0.2.2 lib/rudder/dsl/job.rb
rudder-0.2.1 lib/rudder/dsl/job.rb
rudder-0.2.0 lib/rudder/dsl/job.rb
rudder-0.1.0 lib/rudder/dsl/job.rb