module Pliny::ConfigHelpers
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.
Public Class Methods
add_question_method(attr)
click to toggle source
# 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
Public Instance Methods
mandatory(*attrs)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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