Class: VDNS::Config
- Inherits:
-
Object
- Object
- VDNS::Config
- Defined in:
- lib/vdns/config.rb
Instance Method Summary collapse
- #blank?(name) ⇒ Boolean
- #file_name ⇒ Object
- #get(name) ⇒ Object
- #include?(name) ⇒ Boolean
-
#initialize(file) ⇒ Config
constructor
A new instance of Config.
- #read_file ⇒ Object
- #save_file ⇒ Object
- #set(name, var) ⇒ Object
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.(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
45 46 47 |
# File 'lib/vdns/config.rb', line 45 def blank?(name) @config[name].nil? || @config[name].empty? end |
#file_name ⇒ Object
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
41 42 43 |
# File 'lib/vdns/config.rb', line 41 def include?(name) @config.include? name end |
#read_file ⇒ Object
49 50 51 |
# File 'lib/vdns/config.rb', line 49 def read_file @config = YAML.load_file(@file) end |
#save_file ⇒ Object
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 |