Class: Bolt::Config::Transport::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/config/transport/base.rb

Direct Known Subclasses

Docker, Local, Orch, Remote, SSH, WinRM

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, project = nil) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
20
# File 'lib/bolt/config/transport/base.rb', line 12

def initialize(data = {}, project = nil)
  assert_hash_or_config(data)
  @input    = data
  @resolved = !Bolt::Util.references?(input)
  @config   = resolved? ? Bolt::Util.deep_merge(defaults, filter(input)) : defaults
  @project  = project

  validate if resolved?
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



10
11
12
# File 'lib/bolt/config/transport/base.rb', line 10

def input
  @input
end

Class Method Details

.optionsObject



82
83
84
85
86
87
88
# File 'lib/bolt/config/transport/base.rb', line 82

def self.options
  unless defined? self::OPTIONS
    raise NotImplementedError,
          "Constant OPTIONS must be implemented by the transport config class"
  end
  self::OPTIONS
end

Instance Method Details

#[](key) ⇒ Object

Accessor methods These are mostly all wrappers for same-named Hash methods, but they all require that the config options be fully-resolved before accessing data



25
26
27
# File 'lib/bolt/config/transport/base.rb', line 25

def [](key)
  resolved_config[key]
end

#dig(*keys) ⇒ Object



41
42
43
# File 'lib/bolt/config/transport/base.rb', line 41

def dig(*keys)
  resolved_config.dig(*keys)
end

#fetch(*args) ⇒ Object



33
34
35
# File 'lib/bolt/config/transport/base.rb', line 33

def fetch(*args)
  resolved_config.fetch(*args)
end

#include?(args) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bolt/config/transport/base.rb', line 37

def include?(args)
  resolved_config.include?(args)
end

#merge(*data) ⇒ Object

Merges the original input data with the provided data, which is either a hash or transport config object. Accepts multiple inputs.



58
59
60
61
62
63
64
65
66
# File 'lib/bolt/config/transport/base.rb', line 58

def merge(*data)
  merged = data.compact.inject(@input) do |acc, layer|
    assert_hash_or_config(layer)
    layer_data = layer.is_a?(self.class) ? layer.input : layer
    Bolt::Util.deep_merge(acc, layer_data)
  end

  self.class.new(merged, @project)
end

#resolve(plugins) ⇒ Object

Resolve any references in the input data, then remerge it with the defaults and validate all values



70
71
72
73
74
75
76
# File 'lib/bolt/config/transport/base.rb', line 70

def resolve(plugins)
  @input    = plugins.resolve_references(input)
  @config   = Bolt::Util.deep_merge(defaults, filter(input))
  @resolved = true

  validate
end

#resolved?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/bolt/config/transport/base.rb', line 78

def resolved?
  @resolved
end

#to_hObject



29
30
31
# File 'lib/bolt/config/transport/base.rb', line 29

def to_h
  resolved_config
end