Class: Rudder::DSL::Component

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/rudder/dsl/component.rb

Overview

Base class for other pipeline sub components to extend

Not intended for public usage and subject to change.

Direct Known Subclasses

Job, Resource

Instance Method Summary collapse

Methods included from Util

#_convert_h_val, #_deep_to_h

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, **kwargs) ⇒ Object

Populates the inner hash with missing method names and their arguments

rubocop:disable Style/MethodMissingSuper

Parameters:

  • method (Symbol)

    top level key of this Rudder::DSL::Component Corresponds to the highest level key in a concourse component.

  • *args

    entire arg collection is assigned to the value of the key method. Note: if only 1 argument is provided it is unwrapped from the args Array.

  • **kwargs

    treated as the last value of args if provided

Returns:

  • the value related to method if no arguments or keyword arguments are provided. Otherwise, nil.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rudder/dsl/component.rb', line 43

def method_missing(method, *args, **kwargs)
  # Accessing inner hash as attribute
  return _inner_hash[method] if args.empty? && kwargs.empty?

  # Ruby treats dictionaries passed as the last argument as keyword dicts
  # (specifically when they use symbols as keys). Just smashing
  # these into args so we don't miss anything
  args << kwargs unless kwargs.empty?
  raise "Argument list missing from [#{method}]" if args.empty?

  # If a single arg is given then assume this field is scalar,
  # otherwise assume its a list that needs all args
  formatted_args = args.size == 1 ? args[0] : args
  _inner_hash[method] = formatted_args
end

Instance Method Details

#_inner_hashObject

Required method for all subclasses to implement.

Raises:

  • (RuntimeError)

    if not implemented



19
20
21
# File 'lib/rudder/dsl/component.rb', line 19

def _inner_hash
  raise 'Implement this in a subclass'
end

#respond_to?(_name, _include_all = true) ⇒ Boolean

Components respond to everything by default

Returns:

  • (Boolean)

    true



65
66
67
# File 'lib/rudder/dsl/component.rb', line 65

def respond_to?(_name, _include_all = true)
  true
end

#respond_to_missing?(*_) ⇒ Boolean

Components respond to missing by default

Returns:

  • (Boolean)

    true



74
75
76
# File 'lib/rudder/dsl/component.rb', line 74

def respond_to_missing?(*_)
  true
end

#to_hObject



23
24
25
# File 'lib/rudder/dsl/component.rb', line 23

def to_h
  _deep_to_h(_inner_hash)
end