### EJSON Configuration Example Source: https://github.com/palkan/anyway_config/blob/master/README.md Example content for a secrets.ejson file, demonstrating public key and encrypted values for nested configurations. ```json { "_public_key": "0843d33f0eee994adc66b939fe4ef569e4c97db84e238ff581934ee599e19d1a", "my": { "_username": "root", "password": "EJ[1:IC1d347GkxLXdZ0KrjGaY+ljlsK1BmK7CobFt6iOLgE=:Z55OYS1+On0xEBvxUaIOdv/mE2r6lp44:T7bE5hkAbazBnnH6M8bfVcv8TOQJAgUDQffEgw==]" } } ``` -------------------------------- ### Generate Anyway Install Source: https://github.com/palkan/anyway_config/blob/master/README.md Use this generator to create the base ApplicationConfig class and update .gitignore. You can specify a custom path for static configs. ```ruby rails g anyway:install --configs-path=config/settings ``` ```ruby rails g anyway:install --configs-path=app/configs ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/palkan/anyway_config/blob/master/README.md Example of a YAML configuration file structure for Rails applications, using environments as namespaces. Supports ERB for dynamic values. ```yaml test: host: localhost port: 3002 development: host: localhost port: 3000 ``` -------------------------------- ### YAML with Default and Environment-Specific Settings Source: https://github.com/palkan/anyway_config/blob/master/README.md Example of a YAML configuration using a 'default' key for global settings and an 'staging' key for environment-specific overrides. The 'port' from 'default' is inherited by 'staging'. ```yaml default: server: # This values will be loaded in all environments by default host: localhost port: 3002 staging: server: host: staging.example.com # This value will override the defaults when Rails.env.staging? is true # port will be set to the value from the defaults — 3002 ``` -------------------------------- ### Rails Credentials Configuration Source: https://github.com/palkan/anyway_config/blob/master/README.md Example of configuring a gem using Rails credentials. This method is supported for newer Rails versions. ```yaml my_cool_gem: host: secret.host ``` -------------------------------- ### Handle `on_load` with Type Hints Source: https://github.com/palkan/anyway_config/blob/master/README.md Example demonstrating how to provide type hints for `self` within an `on_load` callback when using `instance_eval`. This is necessary for type checkers to understand the context. ```ruby class MyConfig < Anyway::Config on_load do # @type self : MyConfig raise_validation_error("host is invalid") if host.start_with?("localhost") end end ``` -------------------------------- ### Example Custom Chamber Config Loader Source: https://github.com/palkan/anyway_config/blob/master/README.md Implement a custom loader for Chamber, inheriting from Anyway::Loaders::Base. Handles Chamber errors and returns configuration as a Hash. ```ruby class ChamberConfigLoader < Base def call(name:, **_opts) Chamber.to_hash[name] || {} rescue Chamber::Errors::DecryptionFailure => e warn "Couldn't decrypt Chamber settings: #{e.message}" {} end end Anyway.loaders.insert_before :env, :chamber, ChamberConfigLoader ``` -------------------------------- ### Define Custom Config Class Source: https://github.com/palkan/anyway_config/blob/master/README.md Define a custom configuration class inheriting from `Anyway::Config` to manage specific application settings. This example shows how to define attributes and a custom method. ```ruby # This data is provided by Heroku Dyno Metadadata add-on. class HerokuConfig < Anyway::Config attr_config :app_id, :app_name, :dyno_id, :release_version, :slug_commit def hostname "#{app_name}.herokuapp.com" end end ``` -------------------------------- ### Define a Config Class with RBS Source: https://github.com/palkan/anyway_config/blob/master/README.md Example of defining a configuration class using Anyway::Config, including attribute definitions, type coercions, and required fields. This structure is used to generate RBS type signatures. ```ruby class MyGem::Config < Anyway::Config attr_config :host, port: 8080, tags: [], debug: false coerce_types host: :string, port: :integer, tags: {type: :string, array: true} required :host end ``` -------------------------------- ### Rails Secrets Configuration Source: https://github.com/palkan/anyway_config/blob/master/README.md Example of configuring a gem using `config/secrets.yml`. This is applicable for Rails versions prior to 7.1. For Rails 7.1+, a custom loader needs to be added. ```yaml # config/secrets.yml development: my_cool_gem: port: 4444 ``` -------------------------------- ### Custom Type Coercion with Anyway::Config Source: https://github.com/palkan/anyway_config/blob/master/README.md Shows how to define custom type coercion rules for specific attributes within an Anyway::Config class. This example sets 'port' to string and 'user.dob' to a date type. ```ruby class CoolConfig < Anyway::Config config_name :cool attr_config port: 8080, host: "localhost", user: {name: "admin", password: "admin"} coerce_types port: :string, user: {dob: :date} end ENV["COOL_USER__DOB"] = "1989-07-01" config = CoolConfig.new config.port == "8080" # Even though we defined the default value as int, it's converted into a string config.user["dob"] == Date.new(1989, 7, 1) #=> true ``` -------------------------------- ### Use Custom Config Class in Application Source: https://github.com/palkan/anyway_config/blob/master/README.md Integrate a custom configuration class into your Rails application during initialization. This example sets the Action Mailer hostname using the `HerokuConfig` class. ```ruby config.action_mailer.default_url_options = {host: HerokuConfig.new.hostname} ``` -------------------------------- ### Disable Auto-Casting in Anyway::Config Source: https://github.com/palkan/anyway_config/blob/master/README.md Provides an example of how to disable automatic type casting for all attributes within an Anyway::Config class by calling `disable_auto_cast!`. This ensures all loaded values are treated as strings. ```ruby class CoolConfig < Anyway::Config attr_config port: 8080, host: "localhost", user: {name: "admin", password: "admin"} disable_auto_cast! end ENV["COOL_PORT"] = "443" CoolConfig.new.port == "443" #=> true ``` -------------------------------- ### Pretty Print Configuration Source: https://github.com/palkan/anyway_config/blob/master/README.md Using `pp` to display a formatted overview of the configuration, including value sources and types. ```ruby pp CoolConfig.new ``` -------------------------------- ### Initialize Anyway Config Source: https://github.com/palkan/anyway_config/blob/master/README.md Specify the config file path and environment prefix when initializing Anyway::Config. This allows for flexible configuration loading. ```ruby config = Anyway::Config.for(:my_app, config_path: "my_config.yml", env_prefix: "MYAPP") ``` -------------------------------- ### Instantiate and Access Configuration Source: https://github.com/palkan/anyway_config/blob/master/README.md Create a new instance of your configuration class and access its attributes directly. ```ruby MyCoolGem::Config.new.user #=> "root" ``` -------------------------------- ### Multi-Environment YAML Configuration Source: https://github.com/palkan/anyway_config/blob/master/README.md Demonstrates a YAML configuration where the same settings apply across all environments if specific environment keys are not present. This simplifies configurations that don't vary by environment. ```yaml host: localhost port: 3002 ``` -------------------------------- ### Configure Doppler Loader Source: https://github.com/palkan/anyway_config/blob/master/README.md Set the download URL and token for the Doppler loader. Ensure the DOPPLER_TOKEN environment variable is set. ```ruby Anyway::Loaders::Doppler.download_url = "https://api.doppler.com/v3/configs/config/secrets/download" Anyway::Loaders::Doppler.token = ENV["DOPPLER_TOKEN"] ``` -------------------------------- ### Set Default Config Path Source: https://github.com/palkan/anyway_config/blob/master/README.md Specify the directory path for default configuration files using `config.anyway_config.default_config_path`. ```ruby config.anyway_config.default_config_path = "/etc/configs" ``` ```ruby config.anyway_config.default_config_path = Rails.root.join("etc", "configs") ``` -------------------------------- ### Pattern Matching with AWSConfig Source: https://github.com/palkan/anyway_config/blob/master/README.md Demonstrates using Ruby's pattern matching with configuration objects to conditionally execute code based on attribute values. ```ruby case AWSConfig.new in bucket:, region: "eu-west-1" setup_eu_storage(bucket) in bucket:, region: "us-east-1" setup_us_storage(bucket) end ``` ```ruby aws_configured = case AWSConfig.new in access_key_id:, secret_access_key: true else false end ``` -------------------------------- ### Specify Configuration Sources Source: https://github.com/palkan/anyway_config/blob/master/README.md Limit configuration loading to specific sources for a given Anyway::Config class using 'configuration_sources'. ```ruby class MyConfig < Anyway::Config self.configuration_sources = [:env, :credentials] end ``` -------------------------------- ### Version Compatibility for Overridden Methods Source: https://github.com/palkan/anyway_config/blob/master/README.md Provide backward compatibility for overridden methods between Anyway Config v1.x and v2.0+ by checking for class methods like `.on_load`. ```ruby # Check for the class method added in 2.0, e.g., `.on_load` if respond_to?(:on_load) def url super || (self.url = "#{host}:#{port}") end else def url @url ||= "#{host}:#{port}" end end ``` -------------------------------- ### Dynamic Configuration Loading Source: https://github.com/palkan/anyway_config/blob/master/README.md Fetch configuration values dynamically without a pre-defined schema using `Anyway::Config.for(:config_name)`. This loads data from various sources like YAML files, credentials, secrets, and environment variables. ```ruby # load data from config/my_app.yml, # credentials.my_app, secrets.my_app (if using Rails), ENV["MY_APP_* தூ] # # Given MY_APP_VALUE=42 config = Anyway::Config.for(:my_app) config["value"] #=> 42 ``` -------------------------------- ### Set Default Config Path with Proc Source: https://github.com/palkan/anyway_config/blob/master/README.md Define a Proc for `config.anyway_config.default_config_path` that accepts a config name and returns the specific path for that configuration file. ```ruby config.anyway_config.default_config_path = ->(name) { Rails.root.join("data", "configs", "#{name}.yml") } ``` -------------------------------- ### Test Helper with Environment Variables Source: https://github.com/palkan/anyway_config/blob/master/README.md Using the `with_env` helper for testing configuration under specific environment variable settings. It ensures variables are reset after the block. ```ruby describe HerokuConfig, type: :config do subject { described_class.new } specify do with_env( "HEROKU_APP_NAME" => "kin-web-staging", "HEROKU_APP_ID" => "abc123", "HEROKU_DYNO_ID" => "ddyy", "HEROKU_RELEASE_VERSION" => "v0", "HEROKU_SLUG_COMMIT" => "3e4d5a" ) do is_expected.to have_attributes( app_name: "kin-web-staging", app_id: "abc123", dyno_id: "ddyy", release_version: "v0", slug_commit: "3e4d5a" ) end end end ``` -------------------------------- ### Add Anyway Config Dependency to Project Source: https://github.com/palkan/anyway_config/blob/master/README.md Include the `anyway_config` gem in your project's `Gemfile` for use in applications. ```ruby # Gemfile gem "anyway_config", "~> 2.0" ``` -------------------------------- ### OptionParser Integration for CLI Apps Source: https://github.com/palkan/anyway_config/blob/master/README.md Defining a configuration class that integrates with OptionParser for command-line argument handling. Includes custom option descriptions and flags. ```ruby class MyConfig < Anyway::Config attr_config :host, :log_level, :concurrency, :debug, server_args: {} ignore_options :server_args describe_options( concurrency: "number of threads to use" ) flag_options :debug extend_options do |parser, config| parser.banner = "mycli [options]" parser.on("--server-args VALUE") do |value| config.server_args = JSON.parse(value) end parser.on_tail "-h", "--help" do puts parser end end end config = MyConfig.new config.parse_options!(%w[--host localhost --port 3333 --log-level debug]) config.host # => "localhost" config.port # => 3333 config.log_level # => "debug" config.option_parser ``` ```ruby describe_options( concurrency: { desc: "number of threads to use", type: String } ) ``` -------------------------------- ### Adding Doppler Loader to Anyway Config Source: https://github.com/palkan/anyway_config/blob/master/README.md Shows how to append the Doppler data loader to Anyway's loaders. This enables Anyway Config to pull configuration data from Doppler, requiring the `DOPPLER_TOKEN` environment variable. ```ruby # Add loader Anyway.loaders.append :Doppler, Anyway::Loaders::Doppler ``` -------------------------------- ### List Available Loaders Source: https://github.com/palkan/anyway_config/blob/master/README.md Retrieve a list of available loader identifiers in Anyway Config. ```ruby Anyway.loaders.keys #=> [:yml, :credentials, :env] ``` -------------------------------- ### Trace Configuration Changes Source: https://github.com/palkan/anyway_config/blob/master/README.md Manually changing a configuration value and observing the trace output. This shows how changes are logged. ```ruby conf.host = "anyway.host" conf.to_source_trace["host"] ``` -------------------------------- ### Access Source Trace Information Source: https://github.com/palkan/anyway_config/blob/master/README.md Access tracing information for a configuration instance using the '#to_source_trace' method. ```ruby conf = ExampleConfig.new conf.to_source_trace ``` -------------------------------- ### Reload Configuration Source: https://github.com/palkan/anyway_config/blob/master/README.md Use `#clear` and `#reload` methods to clear and reload configuration settings. `#reload` can also accept an optional Hash for explicit values. ```ruby # Example usage of reload (assuming config object exists) # config.reload # config.reload(user: "new_user") ``` -------------------------------- ### Generate Anyway Config Source: https://github.com/palkan/anyway_config/blob/master/README.md Use this generator to create a named configuration class and optionally its corresponding YAML file. It also creates application_config.rb if it's missing. The --app option places the class in app/configs. ```ruby rails g anyway:config heroku app_id app_name dyno_id release_version slug_commit ``` -------------------------------- ### Define Configuration Class with Defaults Source: https://github.com/palkan/anyway_config/blob/master/README.md Inherit from Anyway::Config and use `attr_config` to define attributes with default values. These values are deeply duplicated for each config instance, preventing mutation issues. ```ruby require "anyway_config" module MyCoolGem class Config < Anyway::Config attr_config user: "root", password: "root", host: "localhost" end end ``` -------------------------------- ### Add Anyway Config Dependency to Gem Source: https://github.com/palkan/anyway_config/blob/master/README.md Specify the `anyway_config` gem as a dependency in your gem's `.gemspec` file to ensure it's available for users. ```ruby # my-cool-gem.gemspec Gem::Specification.new do |spec| # ... spec.add_dependency "anyway_config", ">= 2.0.0" # ... end ``` -------------------------------- ### Add Anyway Config to Steepfile Source: https://github.com/palkan/anyway_config/blob/master/README.md Add these lines to your Steepfile to enable RBS support for Anyway Config and its dependencies. ```ruby library "pathname" library "optparse" library "anyway_config" ``` -------------------------------- ### Customize EJSON Namespace Source: https://github.com/palkan/anyway_config/blob/master/README.md Configure the JSON namespace for EJSON loading within a custom Anyway::Config class. Use 'ejson_namespace' loader option. ```ruby class MyConfig < Anyway::Config loader_options ejson_namespace: "foo" loader_options ejson_namespace: false end ``` -------------------------------- ### Define Configuration Class with Anyway Config Source: https://github.com/palkan/anyway_config/blob/master/README.md Use `Anyway::Config` to define a configuration class for your gem or application. Define parameters and their default values using `attr_config`. ```ruby module Influxer class Config < Anyway::Config attr_config( host: "localhost", username: "root", password: "root" ) end end ``` -------------------------------- ### Custom Loader with Source Tracing Source: https://github.com/palkan/anyway_config/blob/master/README.md Enhance a custom loader to support source tracing by wrapping the returned Hash with '#trace!(:loader_name)'. ```ruby def call(name:, **_opts) trace!(:chamber) do Chamber.to_hash[name] || {} rescue Chamber::Errors::DecryptionFailure => e warn "Couldn't decrypt Chamber settings: #{e.message}" {} end end ``` -------------------------------- ### Define Required Configuration Parameters Source: https://github.com/palkan/anyway_config/blob/master/README.md Use the `required` class method to define parameters that must be present and non-empty in the configuration. This helps ensure essential settings are provided. ```ruby class MyConfig < Anyway::Config attr_config :api_key, :api_secret, :debug required :api_key, :api_secret end MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError ``` -------------------------------- ### Set Default Environmental Key Source: https://github.com/palkan/anyway_config/blob/master/README.md Configure a special top-level key in your YAML file to serve as default values. Anyway Config will load settings under this key first, then merge environment-specific settings. ```ruby config.anyway_config.default_environmental_key = "default" ``` -------------------------------- ### Set Explicit Values During Initialization Source: https://github.com/palkan/anyway_config/blob/master/README.md Pass a Hash to the `.new` method to set specific configuration values explicitly. These values will not be overridden by other sources like YML files or environment variables. ```ruby config = MyCoolGem::Config.new( user: "john", password: "rubyisnotdead" ) # The value would not be overridden from other sources (such as YML file, env) config.user == "john" ``` -------------------------------- ### On-Load Callbacks for Validation Source: https://github.com/palkan/anyway_config/blob/master/README.md Implement custom validation logic using `on_load` callbacks. These callbacks can be defined as method names or blocks and are executed after the configuration is loaded. ```ruby class MyConfig < Anyway::Config attr_config :api_key, :api_secret, :mode on_load :ensure_mode_is_valid on_load do raise_validation_error("API key and/or secret could be blank") if api_key.blank? || api_secret.blank? end def ensure_mode_is_valid unless %w[production test].include?(mode) raise_validation_error "Unknown mode; #{mode}" end end end ``` -------------------------------- ### Add Known Environment Source: https://github.com/palkan/anyway_config/blob/master/README.md Extend the list of known environments by adding a new environment name to `Rails.application.config.anyway_config.known_environments`. ```ruby Rails.application.config.anyway_config.known_environments << "staging" ``` -------------------------------- ### Configure Static Config Path Source: https://github.com/palkan/anyway_config/blob/master/README.md Set a custom path for static configuration files, relative to the Rails root. These configs are loaded before initializers and are not reloaded in development. ```ruby # The path must be relative to Rails root config.anyway_config.autoload_static_config_path = "path/to/configs" ``` -------------------------------- ### Array Env Var Parsing in Ruby Source: https://github.com/palkan/anyway_config/blob/master/README.md Demonstrates how an environment variable with comma-separated values is parsed into a Ruby array. Ensure values with commas are quoted if they should be treated as a single string. ```ruby # Suppose ENV["MYCOOLGEM_IDS"] = '1,2,3' config.ids #=> [1,2,3] ``` ```ruby MYCOOLGEM = "Nif-Nif, Naf-Naf and Nouf-Nouf" ``` -------------------------------- ### Add EJSON Gem Source: https://github.com/palkan/anyway_config/blob/master/README.md Include the EJSON gem in your Gemfile to enable encrypted configuration file support. Ensure the 'ejson' executable is in your PATH. ```ruby gem "ejson" ``` -------------------------------- ### Set Current Environment for YAML Source: https://github.com/palkan/anyway_config/blob/master/README.md Specify the current environment for loading YAML configuration files in non-Rails applications. This can also be set using the ANYWAY_ENV environment variable. ```ruby Anyway::Settings.current_environment = "development" ``` -------------------------------- ### Override Configuration Readers and Writers (v2.0+) Source: https://github.com/palkan/anyway_config/blob/master/README.md Since v2.0, `attr_config` does not populate instance variables. Override readers or writers using `super` or the `values` store to handle type coercion or missing values. ```ruby class MyConfig < Anyway::Config attr_config :host, :port, :url, :meta # override writer to handle type coercion def meta=(val) super(JSON.parse(val)) end # or override reader to handle missing values def url super || (self.url = "#{host}:#{port}") end # until v2.1, it will still be possible to read instance variables, # i.e. the following code would also work def url @url ||= "#{host}:#{port}" end end ``` -------------------------------- ### Set Default YAML Config Path Source: https://github.com/palkan/anyway_config/blob/master/README.md Define the default directory path for YAML configuration files in non-Rails applications. Alternatively, this can be a Proc that returns the path. ```ruby Anyway::Settings.default_config_path = "/etc/configs" ``` ```ruby Anyway::Settings.default_config_path = ->(name) { Rails.root.join("data", "configs", "#{name}.yml") } ``` -------------------------------- ### Configure Rails Inflector Before Initialization Source: https://github.com/palkan/anyway_config/blob/master/README.md If using custom inflection rules for constant name resolution from files, ensure the Rails inflector is configured before application initialization, especially when using static configs. ```ruby # config/application.rb # ... require_relative "initializers/inflections" module SomeApp class Application < Rails::Application # ... end end ``` -------------------------------- ### Specify Configuration Name Source: https://github.com/palkan/anyway_config/blob/master/README.md Use `config_name` to explicitly set the configuration name, especially when the class name doesn't follow default naming conventions. ```ruby module MyCoolGem class Config < Anyway::Config config_name :cool attr_config user: "root", password: "root", host: "localhost", options: {} end end ``` -------------------------------- ### Define Configuration Class without Defaults Source: https://github.com/palkan/anyway_config/blob/master/README.md Use `attr_config` without default values when they are not needed. Non-primitive default values like Hashes or Arrays are safely duplicated. ```ruby attr_config :user, :password, host: "localhost", options: {} ``` -------------------------------- ### Define Environment-Specific Settings Source: https://github.com/palkan/anyway_config/blob/master/README.md When using environmental top-level keys in your YML, all settings must be separated per-environment. You cannot mix environment-specific and global settings at the same level. ```yaml staging: host: localhost # This value will be loaded when Rails.env.staging? is true port: 3002 # This value will not be loaded at all ``` -------------------------------- ### Custom Loader Call Method Signature Source: https://github.com/palkan/anyway_config/blob/master/README.md Defines the signature for the 'call' method in a custom loader. It accepts 'name', 'env_prefix', 'config_path', 'local', and custom 'options'. ```ruby def call( name:, env_prefix:, config_path:, local:, **options ) #=> must return Hash with configuration data end ``` -------------------------------- ### Modify Anyway Loaders Source: https://github.com/palkan/anyway_config/blob/master/README.md Customize the loading order or remove existing loaders from Anyway. Use 'delete' and 'insert_before' methods on Anyway.loaders. ```ruby Anyway.loaders.delete :env Anyway.loaders.insert_before :env, :my_loader, MyLoader ``` -------------------------------- ### Custom Deserializer with Callable Object Source: https://github.com/palkan/anyway_config/blob/master/README.md Illustrates using a custom deserializer by passing a callable object (like a lambda) to `coerce_types`. This allows for complex or custom data transformations during configuration loading. ```ruby COLOR_TO_HEX = lambda do |raw| case raw when "red" "#ff0000" when "green" "#00ff00" when "blue" "#0000ff" end end class CoolConfig < Anyway::Config attr_config :color coerce_types color: COLOR_TO_HEX end CoolConfig.new({color: "red"}).color #=> "#ff0000" ``` -------------------------------- ### Customize Environment Variable Prefix Source: https://github.com/palkan/anyway_config/blob/master/README.md Use `env_prefix` to explicitly set a prefix for environment variables, overriding the default behavior which uses the upper-cased config name. ```ruby module MyCoolGem class Config < Anyway::Config config_name :cool_gem env_prefix :really_cool # now variables, starting wih `REALLY_COOL_`, will be parsed attr_config user: "root", password: "root", host: "localhost", options: {} end end ``` -------------------------------- ### Automatic Predicate Methods for Booleans Source: https://github.com/palkan/anyway_config/blob/master/README.md When boolean attributes have default values (`false` or `true`), Anyway Config automatically adds corresponding predicate methods (e.g., `debug?`). ```ruby attr_config :user, :password, debug: false MyCoolGem::Config.new.debug? #=> false MyCoolGem::Config.new(debug: true).debug? #=> true ``` -------------------------------- ### Environment-Specific Required Parameters Source: https://github.com/palkan/anyway_config/blob/master/README.md The `required` method supports an `env` parameter to specify environments where a parameter is mandatory. This allows for environment-aware validation rules. ```ruby class EnvConfig < Anyway::Config required :password, env: "production" required :maps_api_key, env: :production required :smtp_host, env: %i[production staging] required :aws_bucket, env: %w[production staging] required :anycable_rpc_host, env: {except: :development} required :anycable_redis_url, env: {except: %i[development test]} required :anycable_broadcast_adapter, env: {except: %w[development test]} end ``` -------------------------------- ### Array Type Coercion Definition Source: https://github.com/palkan/anyway_config/blob/master/README.md Illustrates how to define an array type for a configuration attribute using a hash with 'type' and 'array: true'. This is useful for lists of strings or other types. ```ruby # To define an array type, provide a hash with two keys: # - type — elements type # - array: true — mark the parameter as array coerce_types list: {type: :string, array: true} ``` -------------------------------- ### Disable Postponed Load Warning Source: https://github.com/palkan/anyway_config/blob/master/README.md Disable the warning message that appears when Anyway Config is loaded before Rails. This is useful in environments like config/puma.rb. ```ruby Anyway::Rails.disable_postponed_load_warning = true ``` -------------------------------- ### Explicit Non-Array Type Coercion Source: https://github.com/palkan/anyway_config/blob/master/README.md Shows how to explicitly define a non-array type for a configuration attribute using `coerce_types`. This helps prevent confusion and ensures the attribute is treated as a single value. ```ruby coerce_types non_list: :string ``` -------------------------------- ### Array Coercion with Nil Type Source: https://github.com/palkan/anyway_config/blob/master/README.md Demonstrates using `type: nil` within `coerce_types` to convert a value into an array without applying specific element type coercion. This is useful for lists where elements can be strings or hashes. ```ruby # From AnyCable config (sentinels could be represented via strings or hashes) coerce_types redis_sentinels: {type: nil, array: true} ``` -------------------------------- ### Disable Anyway Rails Tracer Source: https://github.com/palkan/anyway_config/blob/master/README.md Completely disable the hook that waits for Rails to be loaded. Use this if you want to prevent Anyway Config from automatically requiring Rails extensions. ```ruby Anyway::Rails.tracer.disable ``` -------------------------------- ### Decrypt EJSON File Source: https://github.com/palkan/anyway_config/blob/master/README.md Command to decrypt an EJSON file directly for debugging purposes. Ensure the 'ejson' executable is available. ```sh ejson decrypt config/secrets.ejson ``` -------------------------------- ### Permitted Classes for YAML Deserialization Source: https://github.com/palkan/anyway_config/blob/master/README.md Configure additional Ruby classes that can be deserialized from YAML. This is useful for custom data types within your configuration. ```ruby Anyway::Loaders::YAML.permitted_classes << Date ``` -------------------------------- ### Generated RBS Type Signature Source: https://github.com/palkan/anyway_config/blob/master/README.md The RBS type signature generated for the `MyGem::Config` class. This signature can be used by type checkers like Steep. ```rbs module MyGem interface _Config def host: () -> String def host=: (String) -> void def port: () -> String? def port=: (String) -> void def tags: () -> Array[String]? def tags=: (Array[String]) -> void def debug: () -> bool def debug?: () -> bool def debug=: (bool) -> void end class Config < Anyway::Config include _Config end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.