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

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

Direct Known Subclasses

Docker, Local, Orch, Remote, SSH, WinRM

Constant Summary

Constants included from Options

Options::LOGIN_SHELLS, Options::RUN_AS_OPTIONS, Options::TRANSPORT_OPTIONS

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.



15
16
17
18
19
20
21
22
23
# File 'lib/bolt/config/transport/base.rb', line 15

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.



13
14
15
# File 'lib/bolt/config/transport/base.rb', line 13

def input
  @input
end

Class Method Details

.optionsObject



85
86
87
88
89
90
91
# File 'lib/bolt/config/transport/base.rb', line 85

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



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

def [](key)
  resolved_config[key]
end

#dig(*keys) ⇒ Object



44
45
46
# File 'lib/bolt/config/transport/base.rb', line 44

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

#fetch(*args) ⇒ Object



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

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

#include?(args) ⇒ Boolean

Returns:

  • (Boolean)


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

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.



61
62
63
64
65
66
67
68
69
# File 'lib/bolt/config/transport/base.rb', line 61

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



73
74
75
76
77
78
79
# File 'lib/bolt/config/transport/base.rb', line 73

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

  validate
end

#resolved?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/bolt/config/transport/base.rb', line 81

def resolved?
  @resolved
end

#to_hObject



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

def to_h
  resolved_config
end