Module: AppConfigurable::ClassMethods
- Defined in:
- lib/app_configurable.rb
Instance Method Summary collapse
-
#config_attributes ⇒ Object
————————————— Service return [Array].
-
#entry(name, default: nil, development: nil, production: nil, staging: nil, test: nil) ⇒ void
Defines a class/instance getters for ‘name`.
-
#env_value_boolean?(value) ⇒ Boolean
return [Boolean].
-
#env_value_falsey?(value) ⇒ Boolean
‘true` if value is falsey.
-
#env_value_truthy?(value) ⇒ Boolean
‘true` if value is truthy.
- #instance ⇒ AppConfigurable
Instance Method Details
#config_attributes ⇒ Object
————————————— Service return [Array]
64 65 66 |
# File 'lib/app_configurable.rb', line 64 def config_attributes @config_attributes end |
#entry(name, default: nil, development: nil, production: nil, staging: nil, test: nil) ⇒ void
This method returns an undefined value.
Returns Defines a class/instance getters for ‘name`.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/app_configurable.rb', line 112 def entry(name, default: nil, development: nil, production: nil, staging: nil, test: nil) # rubocop:disable Metrics/AbcSize defined?(@config_attributes) ? @config_attributes << name : @config_attributes = [name] define_method(name) do preset_value = { development:, production:, staging:, test: }[rails_env.to_sym] if instance_variable_defined?(:"@#{name}") instance_variable_get(:"@#{name}") else instance_variable_set(:"@#{name}", per_env_value_fallback_for(name, default:, preset: preset_value)) end end define_singleton_method(name.to_s, -> { instance.public_send(name) }) AppConfigurable.available_config_attributes << method(name) end |
#env_value_boolean?(value) ⇒ Boolean
return [Boolean]
70 71 72 |
# File 'lib/app_configurable.rb', line 70 def env_value_boolean?(value) env_value_truthy?(value) || env_value_falsey?(value) end |
#env_value_falsey?(value) ⇒ Boolean
‘true` if value is falsey.
# These are falsey.
DEBUG=0
DEBUG=-1
DEBUG=false
DEBUG=f
DEBUG=no
DEBUG=disabled
86 87 88 |
# File 'lib/app_configurable.rb', line 86 def env_value_falsey?(value) %w[0 -1 false f n no disabled].include? value.to_s.downcase end |
#env_value_truthy?(value) ⇒ Boolean
‘true` if value is truthy.
# These are truthy.
DEBUG=1
DEBUG=true
DEBUG=y
DEBUG=yes
DEBUG=enabled
101 102 103 |
# File 'lib/app_configurable.rb', line 101 def env_value_truthy?(value) %w[1 true y yes enabled].include? value.to_s.downcase end |
#instance ⇒ AppConfigurable
130 131 132 |
# File 'lib/app_configurable.rb', line 130 def instance @instance ||= new end |