Module: Patch::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/patch/config.rb

Overview

Deal with config files, hashes

Instance Method Summary collapse

Instance Method Details

#to_hub(nodes_config, options = {}) ⇒ Hub

Parameters:

  • nodes_config (Hash)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :log (IO)

Returns:



12
13
14
15
16
17
# File 'lib/patch/config.rb', line 12

def to_hub(nodes_config, options = {})
  log = Log.new(options.fetch(:log, $>)) unless options[:log].nil?
  nodes = to_nodes(nodes_config, :log => log)
  patches = to_patches(nodes, options[:patches]) unless options[:patches].nil?
  Hub.new(:log => log, :patches => patches)
end

#to_node_maps(nodes, config) ⇒ Array<Node::Map>

Instantiate Node::Map objects given a map config hash

Parameters:

  • nodes (NodeContainer)
  • config (Hash)

Returns:



47
48
49
# File 'lib/patch/config.rb', line 47

def to_node_maps(nodes, config)
  config.map { |from, to| get_node_map(nodes, from, to) }
end

#to_nodes(config, options = {}) ⇒ Node::Container

Instantiate node objects from the given node config or config file

Parameters:

  • config (File, Hash, String)
  • options (Hash) (defaults to: {})

Options Hash (options):

Returns:



37
38
39
40
41
# File 'lib/patch/config.rb', line 37

def to_nodes(config, options = {})
  config = ensure_hash(config)
  node_array = config[:nodes].map { |node_config| to_node(node_config, options) }
  Node::Container.new(node_array)
end

#to_patches(nodes, config) ⇒ Array<Patch>

Instantiate patch objects from the given patch config file, filename or hash

Parameters:

  • nodes (NodeContainer)
  • config (File, Hash, String)

Returns:



23
24
25
26
27
28
29
30
# File 'lib/patch/config.rb', line 23

def to_patches(nodes, config)
  config = ensure_hash(config)
  patches = []
  config[:patches].each do |name, patch_config|
    patches << to_patch(name, nodes, patch_config)
  end
  patches
end