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.



97
98
99
100
101
102
103
104
# File 'lib/ymdp/configuration/config.rb', line 97

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.



95
96
97
# File 'lib/ymdp/configuration/config.rb', line 95

def base
  @base
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  @config.get(base, key)
end

#eachObject



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

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

#exists?(*args) ⇒ Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/ymdp/configuration/config.rb', line 110

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

#file_not_found(filename) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/ymdp/configuration/config.rb', line 124

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



114
115
116
# File 'lib/ymdp/configuration/config.rb', line 114

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