Sha256: 9d33dba2d45182268dc8cc55e7c5b00b7b62908245a485bfa83b3aff5e6ed61f

Contents?: true

Size: 1.15 KB

Versions: 36

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/yaml'

module EacRailsBase0App
  class Application < Rails::Application
    module Envvars
      ENVVARS_FILE_BASENAME = 'envvars'
      ENVVARS_DIRECTORY_NAME = "#{ENVVARS_FILE_BASENAME}.d"
      ENVVARS_FILE_EXTENSIONS = %w[.yml .yaml].freeze

      common_concern do
        setup('envvars')
      end

      module ClassMethods
        def config_root
          ::Rails.root.join('config')
        end

        def envvars_files
          ENVVARS_FILE_EXTENSIONS.flat_map do |extension|
            [config_root.join("#{ENVVARS_FILE_BASENAME}#{extension}")] +
              config_root.join(ENVVARS_DIRECTORY_NAME).glob("*#{extension}")
          end
        end

        def load_envvars_file(path)
          return unless path.exist?

          vars = ::EacRubyUtils::Yaml.load(path.read)
          raise "\"#{path}\" does not contain a Hash" unless vars.is_a?(::Hash)

          vars.each { |name, value| ENV[name.to_s] = value.to_s }
        end

        def setup_envvars
          envvars_files.each { |path| load_envvars_file(path) }
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
eac_rails_base0-0.69.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.7 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.6 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.5 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.4 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.3 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.2 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.1 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.68.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.67.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.66.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.65.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.64.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.63.1 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.63.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.62.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.61.1 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.61.0 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.60.4 lib/eac_rails_base0/app_base/application/envvars.rb
eac_rails_base0-0.60.3 lib/eac_rails_base0/app_base/application/envvars.rb