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

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

Direct Known Subclasses

Docker, Jail, LXD, Local, Orch, Podman, 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.



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

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.



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

def input
  @input
end

Class Method Details

.optionsObject



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

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

.schemaObject



94
95
96
97
98
99
100
# File 'lib/bolt/config/transport/base.rb', line 94

def self.schema
  {
    type:       Hash,
    properties: self::TRANSPORT_OPTIONS.slice(*self::OPTIONS),
    _plugin:    true
  }
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



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

def [](key)
  resolved_config[key]
end

#dig(*keys) ⇒ Object



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

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

#fetch(*args) ⇒ Object



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

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

#include?(args) ⇒ Boolean

Returns:

  • (Boolean)


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

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.



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

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



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

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

  validate
end

#resolved?Boolean

Returns:

  • (Boolean)


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

def resolved?
  @resolved
end

#to_hObject



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

def to_h
  resolved_config
end