Module: AppConfigurable::InstanceMethods
- Defined in:
- lib/app_configurable.rb
Instance Attribute Summary collapse
-
#rails_env ⇒ ActiveSupport::StringInquirer
Default is ‘Rails.env`.
Instance Method Summary collapse
-
#env ⇒ Hash
A copy of the environment for value-reading purposes.
- #initialize(attrs = {}) ⇒ Object
- #submodule_env ⇒ ActiveSupport::StringInquirer/nil
Instance Attribute Details
#rails_env ⇒ ActiveSupport::StringInquirer
Returns Default is ‘Rails.env`.
156 157 158 |
# File 'lib/app_configurable.rb', line 156 def rails_env @rails_env ||= submodule_env || ::Rails.env end |
Instance Method Details
#env ⇒ Hash
A copy of the environment for value-reading purposes.
146 147 148 149 150 151 152 |
# File 'lib/app_configurable.rb', line 146 def env @env ||= begin result = ::Rails.env == rails_env ? ENV.to_h : ::Dotenv.parse(".env.#{rails_env}") result.deep_transform_keys!(&:downcase).with_indifferent_access end end |
#initialize(attrs = {}) ⇒ Object
140 141 142 |
# File 'lib/app_configurable.rb', line 140 def initialize(attrs = {}) attrs.each { |k, v| public_send(:"#{k}=", v) } end |
#submodule_env ⇒ ActiveSupport::StringInquirer/nil
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/app_configurable.rb', line 172 def submodule_env @submodule_env ||= begin class_name = self.class.name if class_name selector = "#{class_name.parameterize(separator: "_")}_ENV" env_string = ENV.fetch(selector.upcase, nil) ActiveSupport::StringInquirer.new(env_string) if env_string end end end |