Module: AppConfigurable::InstanceMethods

Defined in:
lib/app_configurable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rails_envActiveSupport::StringInquirer

Returns Default is ‘Rails.env`.

Returns:

  • (ActiveSupport::StringInquirer)

    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

#envHash

A copy of the environment for value-reading purposes.

Returns:

  • (Hash)


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_envActiveSupport::StringInquirer/nil

Returns:

  • (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