Sha256: d292e2295b1cdee91e582a4e8854d64819dc50c6755d000ae873c57b4ea505ac

Contents?: true

Size: 914 Bytes

Versions: 1

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

module Runger
  # Adds ability to generate anonymous (class-less) config dynamicly
  # (like Rails.application.config_for but using more data sources).
  module 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

        AutoCast.call(raw_config)
      end
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
runger_config-4.0.0 lib/runger/dynamic_config.rb