Class: VDNS::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vdns/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vdns/config.rb', line 7

def initialize(file)
  @file = File.expand_path(file)

  unless File.exist?(@file)
    dirname = File.dirname(@file)
    Dir.mkdir(dirname) unless Dir.exist?(dirname)
    File.open(@file, "w") do |f|
      f.puts %Q(
user: #{`whoami`}
domain:
provider: aws-route53

aws_r53_access_key: 
aws_r53_secret_access_key: 
aws_r53_hosted_zone_id:
)
    end
  end

  read_file
end

Instance Method Details

#blank?(name) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/vdns/config.rb', line 45

def blank?(name)
  @config[name].nil? || @config[name].empty?
end

#file_nameObject



59
60
61
# File 'lib/vdns/config.rb', line 59

def file_name
  @file
end

#get(name) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/vdns/config.rb', line 29

def get(name)
  if include?(name)
    @config[name]
  else
    raise ArgumentError, "Undefined config variable #{name}"
  end
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/vdns/config.rb', line 41

def include?(name)
  @config.include? name
end

#read_fileObject



49
50
51
# File 'lib/vdns/config.rb', line 49

def read_file
  @config = YAML.load_file(@file)
end

#save_fileObject



53
54
55
56
57
# File 'lib/vdns/config.rb', line 53

def save_file
  File.open(@file, 'w') do |f|
    f.puts YAML.dump(@config)
  end
end

#set(name, var) ⇒ Object



37
38
39
# File 'lib/vdns/config.rb', line 37

def set(name, var)
  @config[name] = var
end