Class: Sumodev::Config
- Inherits:
-
Object
- Object
- Sumodev::Config
- Includes:
- Singleton
- Defined in:
- lib/sumodev/config.rb
Constant Summary collapse
- Defaults =
{ 'SUMO_TEMP_PATH' => "/tmp/", 'SUMO_FORWARD_PORTS' => 'true' }
Instance Attribute Summary collapse
-
#variables ⇒ Object
Returns the value of attribute variables.
Class Method Summary collapse
Instance Method Summary collapse
- #get(name) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #true?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sumodev/config.rb', line 23 def initialize sumofile_path = File.("~/.sumorc") if File.file?(sumofile_path) @variables = File.readlines(sumofile_path).inject({}) do |env, line| line.chomp! next if line.empty? line = line.strip.gsub('export', '') name, value = line.split("=", 2) env.merge name.strip => value.strip.tr("'\"", '') end else raise("No .sumorc-file found in ~/.sumorc") end end |
Instance Attribute Details
#variables ⇒ Object
Returns the value of attribute variables.
6 7 8 |
# File 'lib/sumodev/config.rb', line 6 def variables @variables end |
Class Method Details
.get(*args) ⇒ Object
9 10 11 |
# File 'lib/sumodev/config.rb', line 9 def get(*args) instance.get(*args) end |
.true?(*args) ⇒ Boolean
13 14 15 |
# File 'lib/sumodev/config.rb', line 13 def true?(*args) instance.true?(*args) end |
Instance Method Details
#get(name) ⇒ Object
40 41 42 |
# File 'lib/sumodev/config.rb', line 40 def get(name) @variables[name] || Defaults[name] || raise("Can't find setting for #{name} in ~/.sumorc") end |
#true?(name) ⇒ Boolean
44 45 46 |
# File 'lib/sumodev/config.rb', line 44 def true?(name) ['1', 'true', 'yes', 't', 'y'].member?(get(name).downcase) end |