Sha256: 67c31f61ff35a7a0b0836464d5323793f161571ece15f5bccd7a25ff65e1bdbe

Contents?: true

Size: 919 Bytes

Versions: 19

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

module Anyway
  # 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 = Anyway::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: 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

19 entries across 19 versions & 1 rubygems

Version Path
anyway_config-2.6.4 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.6.3 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.6.2 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.6.1 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.6.0 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.5.4 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.5.3 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.5.2 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.5.1 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.5.0 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.4.2 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.4.1 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.4.0 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.3.1 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.3.0 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.2.3 lib/.rbnext/3.1/anyway/dynamic_config.rb
anyway_config-2.2.2 lib/.rbnext/1995.next/anyway/dynamic_config.rb
anyway_config-2.2.1 lib/.rbnext/1995.next/anyway/dynamic_config.rb
anyway_config-2.2.0 lib/.rbnext/1995.next/anyway/dynamic_config.rb