Sha256: f3797af950e1b17057a69ee66d0f12d0b8cb551b50b5c5944d00c507fb3d6384

Contents?: true

Size: 867 Bytes

Versions: 3

Compression:

Stored size: 867 Bytes

Contents

# frozen_string_literal: true

# Adds ability to generate anonymous (class-less) config dynamicly
# (like Rails.application.config_for but using more data sources).
module Runger::DynamicConfig
  module ClassMethods
    # Load config as Hash by any name
    #
    # Example:
    #
    #   my_config = Runger::Config.for(:my_app)
    #   # will load data from config/my_app.yml, secrets.my_app, ENV["MY_APP_*"]
    #
    def for(name, auto_cast: true, **options)
      config = allocate
      options[:env_prefix] ||= name.to_s.upcase
      options[:config_path] ||= config.resolve_config_path(name, options[:env_prefix])

      raw_config = config.load_from_sources(new_empty_config, name:, **options)
      return raw_config unless auto_cast

      ::Runger::AutoCast.call(raw_config)
    end
  end

  def self.included(base)
    base.extend(ClassMethods)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
runger_config-5.2.0 lib/runger/dynamic_config.rb
runger_config-5.1.0 lib/runger/dynamic_config.rb
runger_config-5.0.0 lib/runger/dynamic_config.rb