Class: Dnsign::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsign/config_loader.rb

Defined Under Namespace

Classes: Config

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigLoader

Returns a new instance of ConfigLoader.


9
10
11
# File 'lib/dnsign/config_loader.rb', line 9

def initialize
  @config = Config.new
end

Class Method Details

.parse_and_load(params) ⇒ Object


42
43
44
45
46
# File 'lib/dnsign/config_loader.rb', line 42

def self.parse_and_load(params)
  loader = self.new
  config = loader.parse params
  loader.load config.path
end

Instance Method Details

#load(path) ⇒ Object


32
33
34
35
36
37
38
39
40
# File 'lib/dnsign/config_loader.rb', line 32

def load(path)
  config = YAML.load_file path

  # symbolize keys
  config.reduce({}) do |acc, (k,v)|
    acc[k.to_sym] = v
    acc
  end
end

#parse(params) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dnsign/config_loader.rb', line 13

def parse(params)
  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: ruby dyndns.rb [options]"

    opts.on("-cCONFIG", "--config=CONFIG", "Path to config file") do |c|
      @config.path = c
    end

    opts.on("-h", "--help", "Prints this help") do
      puts opts
      exit
    end
  end

  opt_parser.parse! params

  return @config
end