module Pliny::CastingConfigHelpers
Public Instance Methods
array(method = nil)
click to toggle source
bool()
click to toggle source
# File lib/pliny/config_helpers.rb, line 26 def bool ->(v) { v.to_s=='true'} end
float()
click to toggle source
# File lib/pliny/config_helpers.rb, line 22 def float ->(v) { v.to_f } end
int()
click to toggle source
# File lib/pliny/config_helpers.rb, line 18 def int ->(v) { v.to_i } end
mandatory(name, method=nil)
click to toggle source
# File lib/pliny/config_helpers.rb, line 3 def mandatory(name, method=nil) value = cast(ENV.fetch(name.to_s.upcase), method) create(name, value) end
optional(name, method=nil)
click to toggle source
# File lib/pliny/config_helpers.rb, line 8 def optional(name, method=nil) value = cast(ENV[name.to_s.upcase], method) create(name, value) end
override(name, default, method=nil)
click to toggle source
# File lib/pliny/config_helpers.rb, line 13 def override(name, default, method=nil) value = cast(ENV.fetch(name.to_s.upcase, default), method) create(name, value) end
pliny_env()
click to toggle source
DEPRECATED: pliny_env
is deprecated in favour of app_env.
See more at https://github.com/interagent/pliny/issues/277
This method is kept temporary in case it is used somewhere in the app.
# File lib/pliny/config_helpers.rb, line 64 def pliny_env warn "Config.pliny_env is deprecated and will be removed, " \ "use Config.app_env instead." env end
rack_env()
click to toggle source
# File lib/pliny/config_helpers.rb, line 52 def rack_env if env == "development" || env == "test" "development" else "deployment" end end
string()
click to toggle source
# File lib/pliny/config_helpers.rb, line 30 def string nil end
symbol()
click to toggle source
# File lib/pliny/config_helpers.rb, line 34 def symbol ->(v) { v.to_sym } end
Private Instance Methods
cast(value, method)
click to toggle source
# File lib/pliny/config_helpers.rb, line 72 def cast(value, method) method ? method.call(value) : value end
create(name, value)
click to toggle source
# File lib/pliny/config_helpers.rb, line 76 def create(name, value) instance_variable_set(:"@#{name}", value) instance_eval "def #{name}; @#{name} end", __FILE__, __LINE__ if value.kind_of?(TrueClass) || value.kind_of?(FalseClass) || value.kind_of?(NilClass) instance_eval "def #{name}?; !!@#{name} end", __FILE__, __LINE__ end end
env()
click to toggle source
This method helps with transition from PLINY_ENV to APP_ENV.
# File lib/pliny/config_helpers.rb, line 85 def env legacy_env || app_env end
legacy_env()
click to toggle source
PLINY_ENV is deprecated, but it might be still used by someone.
# File lib/pliny/config_helpers.rb, line 90 def legacy_env if ENV.key?('PLINY_ENV') warn "PLINY_ENV is deprecated in favour of APP_ENV, " \ "update .env file or application configuration." ENV['PLINY_ENV'] end end