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.



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

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.



97
98
99
# File 'lib/ymdp/configuration/config.rb', line 97

def base
  @base
end

Instance Method Details

#[](key) ⇒ Object



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

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

#eachObject



120
121
122
123
124
# File 'lib/ymdp/configuration/config.rb', line 120

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

#exists?(*args) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/ymdp/configuration/config.rb', line 112

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

#file_not_found(filename) ⇒ Object



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

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



116
117
118
# File 'lib/ymdp/configuration/config.rb', line 116

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