Class: YMDP::Configuration::Base

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

Direct Known Subclasses

Config, Servers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, base) ⇒ Base

Returns a new instance of Base.



109
110
111
112
113
114
115
116
# File 'lib/ymdp/configuration/config.rb', line 109

def initialize(filename, base)
  if File.exists?(filename)
    @config = Serenity::Configuration.new(filename)
    @base = base
  else
    file_not_found(filename)
  end
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



107
108
109
# File 'lib/ymdp/configuration/config.rb', line 107

def base
  @base
end

Instance Method Details

#[](key) ⇒ Object



118
119
120
121
122
# File 'lib/ymdp/configuration/config.rb', line 118

def [](key)
  @config.get(base, key)
rescue StandardError => e
  raise ArgumentError.new("Could not find #{base}, #{key}")
end

#eachObject



132
133
134
135
136
# File 'lib/ymdp/configuration/config.rb', line 132

def each
  options.each do |name, values|
    yield name, values
  end
end

#exists?(*args) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/ymdp/configuration/config.rb', line 124

def exists?(*args)
  @config.exists?(base, *args)
end

#file_not_found(filename) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/ymdp/configuration/config.rb', line 138

def file_not_found(filename)
  $stdout.puts
  $stdout.puts "Create #{filename} with the following command:\n\n  ./script/config" 
  $stdout.puts
  
  raise "File not found: #{filename}"
end

#options(*args) ⇒ Object



128
129
130
# File 'lib/ymdp/configuration/config.rb', line 128

def options(*args)
  @config.get(base, *args)
end