Module: Pliny::ConfigHelpers
- Defined in:
- lib/pliny/config_helpers.rb
Overview
DEPRECATED: ConfigHelpers was a slightly more primitive version of CastingConfigHelpers above that didn’t contain any of the latter’s features around typing. It’s been left here for backwards compatibility in apps based on old templates that may be using it.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.add_question_method(attr) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/pliny/config_helpers.rb', line 126 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
112 113 114 115 116 117 |
# File 'lib/pliny/config_helpers.rb', line 112 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
105 106 107 108 109 110 |
# File 'lib/pliny/config_helpers.rb', line 105 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
119 120 121 122 123 124 |
# File 'lib/pliny/config_helpers.rb', line 119 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 |