Class: TBM::ConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/TBM/config_parser.rb

Constant Summary collapse

CONFIG_FILE =

The configuration file used for parsing config.

File.expand_path( '~/.tbm' )
GATEWAY_PATTERN =
/^([^@]+)(@([^@]+))?$/

Class Method Summary collapse

Class Method Details

.parseConfig

Parses the tunnel boring machine configuration to get a list of targets which can be invoked to bore tunnels.

Returns:

  • (Config)

    the parsed configuration for TBM



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/TBM/config_parser.rb', line 16

def self.parse
  config = Config.new
  if File.file? CONFIG_FILE
    config_data = YAML.load_file( CONFIG_FILE )
    case config_data
    when Hash
      parse_gateways( config_data, config ) if config_data.is_a? Hash
    else
      config.errors << "Cannot parse TBM configuration of type: #{config_data.class}"
    end
  else
    config.errors << "No configuration file found. Specify your tunnels in YAML form in: ~/.tunnels"
  end
  return config
rescue Psych::SyntaxError => pse
  config.errors << "TBM config is invalid YAML: #{pse}"
  return config
end