Class: YMDP::Configuration::Base
- Inherits:
-
Object
- Object
- YMDP::Configuration::Base
- Defined in:
- lib/ymdp/configuration/config.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each ⇒ Object
- #exists?(*args) ⇒ Boolean
- #file_not_found(filename) ⇒ Object
-
#initialize(filename, base) ⇒ Base
constructor
A new instance of Base.
- #options(*args) ⇒ Object
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
#base ⇒ Object
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 |
#each ⇒ Object
132 133 134 135 136 |
# File 'lib/ymdp/configuration/config.rb', line 132 def each .each do |name, values| yield name, values end end |
#exists?(*args) ⇒ 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 (*args) @config.get(base, *args) end |