Module: Diplo::Env
- Defined in:
- lib/diplo/env.rb
Class Method Summary collapse
- .fetch(variable) ⇒ Object
- .fetch_converted(variable, conversion, error = nil) ⇒ Object
- .fetch_float(variable, error = nil, &block) ⇒ Object
- .fetch_int(variable, error = nil, &block) ⇒ Object
Class Method Details
.fetch(variable) ⇒ Object
9 10 11 12 13 |
# File 'lib/diplo/env.rb', line 9 def fetch(variable) ENV["DIPLO_#{variable.to_s.upcase}"] || begin yield if block_given? end end |
.fetch_converted(variable, conversion, error = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/diplo/env.rb', line 23 def fetch_converted(variable, conversion, error = nil) value = fetch(variable) return yield if value.nil? && block_given? send conversion, value rescue error ? raise(error) : raise end |
.fetch_float(variable, error = nil, &block) ⇒ Object
19 20 21 |
# File 'lib/diplo/env.rb', line 19 def fetch_float(variable, error = nil, &block) fetch_converted variable, :Float, error, &block end |
.fetch_int(variable, error = nil, &block) ⇒ Object
15 16 17 |
# File 'lib/diplo/env.rb', line 15 def fetch_int(variable, error = nil, &block) fetch_converted variable, :Integer, error, &block end |