Module: Pliny::ConfigHelpers
- Defined in:
- lib/pliny/config_helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.add_question_method(attr) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/pliny/config_helpers.rb', line 89 def self.add_question_method(attr) define_method "#{attr}?" do return false if send(attr).nil? !!(send(attr) =~ /\Atrue|yes|on\z/i || send(attr).to_i > 0) end end |
Instance Method Details
#mandatory(*attrs) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/pliny/config_helpers.rb', line 75 def mandatory(*attrs) attrs.each do |attr| instance_eval "def #{attr}; @#{attr} ||= ENV['#{attr.upcase}'] || raise('missing=#{attr.upcase}') end", __FILE__, __LINE__ ConfigHelpers.add_question_method(attr) end end |
#optional(*attrs) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/pliny/config_helpers.rb', line 68 def optional(*attrs) attrs.each do |attr| instance_eval "def #{attr}; @#{attr} ||= ENV['#{attr.upcase}'] end", __FILE__, __LINE__ ConfigHelpers.add_question_method(attr) end end |
#override(attrs) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/pliny/config_helpers.rb', line 82 def override(attrs) attrs.each do |attr, value| instance_eval "def #{attr}; @#{attr} ||= ENV['#{attr.upcase}'] || '#{value}'.to_s end", __FILE__, __LINE__ ConfigHelpers.add_question_method(attr) end end |