[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8025":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":34,"readmeContent":35,"aiSummary":36,"trendingCount":16,"starSnapshotCount":16,"syncStatus":37,"lastSyncTime":38,"discoverSource":39},8025,"config","rubyconfig\u002Fconfig","rubyconfig","Easiest way to add multi-environment yaml settings to Rails, Sinatra, Padrino and other Ruby projects.","",null,"Ruby",2170,231,27,15,0,1,4,29.1,"Other",false,"master",[5,24,25,26,27,28,29,30,31,32,33],"configuration","configuration-management","environment-variables","environments","padrino","rails","ruby","ruby-on-rails","settings","sinatra","2026-06-12 02:01:47","# Config\n\n[![Version](https:\u002F\u002Fimg.shields.io\u002Fgem\u002Fv\u002Fconfig)](https:\u002F\u002Frubygems.org\u002Fgems\u002Fconfig)\n[![Downloads Total](https:\u002F\u002Fimg.shields.io\u002Fgem\u002Fdt\u002Fconfig)](https:\u002F\u002Frubygems.org\u002Fgems\u002Fconfig)\n[![Tests](https:\u002F\u002Fgithub.com\u002Frubyconfig\u002Fconfig\u002Fworkflows\u002Ftests\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Frubyconfig\u002Fconfig\u002Factions?query=branch%3Amaster)\n[![Financial Contributors on Open Collective](https:\u002F\u002Fopencollective.com\u002Frubyconfig\u002Fall\u002Fbadge.svg?label=backers)](https:\u002F\u002Fopencollective.com\u002Frubyconfig)\n\n## Summary\n\nConfig helps you easily manage environment specific settings in an easy and usable manner.\n\n## Features\n\n* simple YAML config files\n* config files support ERB\n* config files support inheritance and multiple environments\n* access config information via convenient object member notation\n* support for multi-level settings (`Settings.group.subgroup.setting`)\n* local developer settings ignored when committing the code\n\n## Compatibility\n\nCurrent version supports and is [tested](.github\u002Fworkflows\u002Ftests.yml#L19) for the following interpreters and frameworks:\n\n* Interpreters\n  * [Ruby](https:\u002F\u002Fwww.ruby-lang.org) `>= 2.6`\n  * [JRuby](https:\u002F\u002Fwww.jruby.org) `>= 9.2`\n  * [TruffleRuby](https:\u002F\u002Fgithub.com\u002Foracle\u002Ftruffleruby) `>= 19.3`\n* Application frameworks\n  * Rails `>= 5.2`\n  * Padrino\n  * Sinatra\n\nFor Ruby `2.0` to `2.3` or Rails `3` to `4.1` use version `1.x` of this gem. For older versions of Rails or Ruby use [AppConfig](http:\u002F\u002Fgithub.com\u002Ffredwu\u002Fapp_config).\n\nFor Ruby `2.4` or `2.5` or Rails `4.2`, `5.0`, or `5.1` use version `3.x` of this gem.\n\n## Installing\n\n### Installing on Rails\n\nAdd `gem 'config'` to your `Gemfile` and run `bundle install` to install it. Then run\n\n    rails g config:install\n\nwhich will generate customizable config file `config\u002Finitializers\u002Fconfig.rb` and set of default settings files:\n\n    config\u002Fsettings.yml\n    config\u002Fsettings.local.yml\n    config\u002Fsettings\u002Fdevelopment.yml\n    config\u002Fsettings\u002Fproduction.yml\n    config\u002Fsettings\u002Ftest.yml\n\nYou can now edit them to adjust to your needs.\n\n> Note: By default, the config environment will match the Rails environment (`Rails.env`). This can be changed by setting `config.environment`.\n\n### Installing on Padrino\n\nAdd the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config`\n\n```ruby\nregister Config\n```\n\n### Installing on Sinatra\n\nAdd the gem to your `Gemfile` and run `bundle install` to install it. Afterwards in need to register `Config` in your app and give it a root so it can find the config files.\n\n```ruby\nset :root, File.dirname(__FILE__)\nregister Config\n```\n\n### Installing on other ruby projects\n\nAdd the gem to your `Gemfile` and run `bundle install` to install it. Then initialize `Config` manually within your configure block.\n\n```ruby\nConfig.load_and_set_settings(Config.setting_files(\"\u002Fpath\u002Fto\u002Fconfig_root\", \"your_project_environment\"))\n```\n\nIt's also possible to initialize `Config` manually within your configure block if you want to just give it some yml paths to load from.\n\n```ruby\nConfig.load_and_set_settings(\"\u002Fpath\u002Fto\u002Fyaml1\", \"\u002Fpath\u002Fto\u002Fyaml2\", ...)\n```\n\n## Accessing the Settings object\n\nAfter installing the gem, `Settings` object will become available globally and by default will be compiled from the files listed below. Settings defined in files that are lower in the list override settings higher.\n\n    config\u002Fsettings.yml\n    config\u002Fsettings\u002F#{environment}.yml\n    config\u002Fenvironments\u002F#{environment}.yml\n\n    config\u002Fsettings.local.yml\n    config\u002Fsettings\u002F#{environment}.local.yml\n    config\u002Fenvironments\u002F#{environment}.local.yml\n\nEntries can be accessed via object member notation:\n\n```ruby\nSettings.my_config_entry\n```\n\nNested entries are supported:\n\n```ruby\nSettings.my_section.some_entry\n```\n\nAlternatively, you can also use the `[]` operator if you don't know which exact setting you need to access ahead of time.\n\n```ruby\n# All the following are equivalent to Settings.my_section.some_entry\nSettings.my_section[:some_entry]\nSettings.my_section['some_entry']\nSettings[:my_section][:some_entry]\n```\n\n### Reloading settings\n\nYou can reload the Settings object at any time by running `Settings.reload!`.\n\n### Reloading settings and config files\n\nYou can also reload the `Settings` object from different config files at runtime.\n\nFor example, in your tests if you want to test the production settings, you can:\n\n```ruby\nRails.env = \"production\"\nSettings.reload_from_files(\n  Rails.root.join(\"config\", \"settings.yml\").to_s,\n  Rails.root.join(\"config\", \"settings\", \"#{Rails.env}.yml\").to_s,\n  Rails.root.join(\"config\", \"environments\", \"#{Rails.env}.yml\").to_s\n)\n```\n\n### Environment specific config files\n\nYou can have environment specific config files. Environment specific config entries take precedence over common config entries.\n\nExample development environment config file:\n\n```ruby\n#{Rails.root}\u002Fconfig\u002Fenvironments\u002Fdevelopment.yml\n```\n\nExample production environment config file:\n\n```ruby\n#{Rails.root}\u002Fconfig\u002Fenvironments\u002Fproduction.yml\n```\n\n### Extra sources\n\nYou can load extra sources during initialization by setting the `extra_sources` configuration option.\n\n```ruby\nConfig.setup do |config|\n  config.extra_sources = [\n    'path\u002Fto\u002Fextra_source.yml',          # String: loads extra_source.yml\n    { api_key: ENV['API_KEY'] },         # Hash: direct hash source\n    MyCustomSource.new,                  # Object: custom source object that responds to `load`\n  ]\nend\n```\n\nThis will also overwrite the same config entries from the main file.\n\n### Developer specific config files\n\nIf you want to have local settings, specific to your machine or development environment, you can use the following files, which are automatically `.gitignore` :\n\n```ruby\nRails.root.join(\"config\", \"settings.local.yml\").to_s,\nRails.root.join(\"config\", \"settings\", \"#{Rails.env}.local.yml\").to_s,\nRails.root.join(\"config\", \"environments\", \"#{Rails.env}.local.yml\").to_s\n```\n\n**NOTE:** The file `settings.local.yml` will not be loaded in tests to prevent local configuration from causing flaky or non-deterministic tests. Environment-specific files (e.g. `settings\u002Ftest.local.yml`) will still be loaded to allow test-specific credentials.\n\n### Adding sources at runtime\n\nYou can add new YAML config files at runtime. Just use:\n\n```ruby\nSettings.add_source!(\"\u002Fpath\u002Fto\u002Fsource.yml\")\nSettings.reload!\n```\n\nThis will use the given source.yml file and use its settings to overwrite any previous ones.\n\nOn the other hand, you can prepend a YML file to the list of configuration files:\n\n```ruby\nSettings.prepend_source!(\"\u002Fpath\u002Fto\u002Fsource.yml\")\nSettings.reload!\n```\n\nThis will do the same as `add_source`, but the given YML file will be loaded first (instead of last) and its settings will be overwritten by any other configuration file. This is especially useful if you want to define defaults.\n\nOne thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent per developer). Then I create a new initializer in `config\u002Finitializers\u002Fadd_local_config.rb` with the contents\n\n```ruby\nSettings.add_source!(\"#{Rails.root}\u002Fconfig\u002Fsettings\u002Flocal.yml\")\nSettings.reload!\n```\n\n> Note: this is an example usage, it is easier to just use the default local\n> files `settings.local.yml`, `settings\u002F#{Rails.env}.local.yml` and\n> `environments\u002F#{Rails.env}.local.yml` for your developer specific settings.\n\nYou also have the option to add a raw hash as a source. One use case might be storing settings in the database or in environment variables that overwrite what is in the YML files.\n\n```ruby\nSettings.add_source!({some_secret: ENV['some_secret']})\nSettings.reload!\n```\n\nYou may pass a hash to `prepend_source!` as well.\n\n## Embedded Ruby (ERB)\n\nEmbedded Ruby is allowed in the YAML configuration files. ERB will be evaluated at load time by default, and when the `evaluate_erb_in_yaml` configuration is set to `true`.\n\nConsider the two following config files.\n\n* ```#{Rails.root}\u002Fconfig\u002Fsettings.yml```\n\n```yaml\nsize: 1\nserver: google.com\n```\n\n* ```#{Rails.root}\u002Fconfig\u002Fenvironments\u002Fdevelopment.yml```\n\n```yaml\nsize: 2\ncomputed: \u003C%= 1 + 2 + 3 %>\nsection:\n  size: 3\n  servers: [ {name: yahoo.com}, {name: amazon.com} ]\n```\n\nNotice that the environment specific config entries overwrite the common entries.\n\n```ruby\nSettings.size   # => 2\nSettings.server # => google.com\n```\n\nNotice the embedded Ruby.\n\n```ruby\nSettings.computed # => 6\n```\n\nNotice that object member notation is maintained even in nested entries.\n\n```ruby\nSettings.section.size # => 3\n```\n\nNotice array notation and object member notation is maintained.\n\n```ruby\nSettings.section.servers[0].name # => yahoo.com\nSettings.section.servers[1].name # => amazon.com\n```\n\n## Configuration\n\nThere are multiple configuration options available, however you can customize `Config` only once, preferably during application initialization phase:\n\n```ruby\nConfig.setup do |config|\n  config.const_name = 'Settings'\n  # ...\nend\n```\n\nAfter installing `Config` in Rails, you will find automatically generated file that contains default configuration located at `config\u002Finitializers\u002Fconfig.rb`.\n\n### General\n\n* `const_name` - name of the object holding your settings. Default: `'Settings'`\n* `evaluate_erb_in_yaml` - evaluate ERB in YAML config files. Set to false if the config file contains ERB that should not be evaluated at load time. Default: `true`\n* `file_name` - name of the file to store general keys accessible in all environments. Default: `'settings'` - located at `config\u002Fsettings.yml`\n* `dir_name` - name of the directory to store environment-specific files. Default: `'settings'` - located at `config\u002Fsettings\u002F`\n\n### Merge customization\n\n* `overwrite_arrays` - overwrite arrays found in previously loaded settings file. Default: `true`\n* `merge_hash_arrays` - merge hashes inside of arrays from previously loaded settings files. Makes sense only when `overwrite_arrays = false`. Default: `false`\n* `knockout_prefix` - ability to remove elements of the array set in earlier loaded settings file. Makes sense only when `overwrite_arrays = false`, otherwise array settings would be overwritten by default. Default: `nil`\n* `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`.\n\n```ruby\n# merge_nil_values is true by default\nc = Config.load_files(\".\u002Fspec\u002Ffixtures\u002Fdevelopment.yml\") # => #\u003CConfig::Options size=2, ...>\nc.size # => 2\nc.merge!(size: nil) => #\u003CConfig::Options size=nil, ...>\nc.size # => nil\n```\n\n```ruby\n# To reject nil values when merging settings:\nConfig.setup do |config|\n  config.merge_nil_values = false\nend\n\nc = Config.load_files(\".\u002Fspec\u002Ffixtures\u002Fdevelopment.yml\") # => #\u003CConfig::Options size=2, ...>\nc.size # => 2\nc.merge!(size: nil) => #\u003CConfig::Options size=nil, ...>\nc.size # => 2\n```\n\nCheck [Deep Merge](https:\u002F\u002Fgithub.com\u002Fdanielsdeleo\u002Fdeep_merge) for more details.\n\n### Validation\n\nWith Ruby 2.1 or newer, you can optionally define a [schema](https:\u002F\u002Fgithub.com\u002Fdry-rb\u002Fdry-schema) or [contract](https:\u002F\u002Fgithub.com\u002Fdry-rb\u002Fdry-validation) (added in `config-2.1`) using [dry-rb](https:\u002F\u002Fgithub.com\u002Fdry-rb) to validate presence (and type) of specific config values. Generally speaking contracts allow to describe more complex validations with depencecies between fields.\n\nIf you provide either validation option (or both) it will automatically be used to validate your config. If validation fails it will raise a `Config::Validation::Error` containing information about all the mismatches between the schema and your config.\n\nBoth examples below demonstrates how to ensure that the configuration has an optional `email` and the `youtube` structure with the `api_key` field filled. The contract adds an additional rule.\n\n#### Contract\n\nLeverage dry-validation, you can create a contract with a params schema and rules:\n\n```ruby\nclass ConfigContract \u003C Dry::Validation::Contract\n  params do\n    optional(:email).maybe(:str?)\n\n    required(:youtube).schema do\n      required(:api_key).filled\n    end\n  end\n\n  rule(:email) do\n    unless \u002F\\A[\\w+\\-.]+@[a-z\\d\\-]+(\\.[a-z\\d\\-]+)*\\.[a-z]+\\z\u002Fi.match?(value)\n      key.failure('has invalid format')\n    end\n  end\nend\n\nConfig.setup do |config|\n  config.validation_contract = ConfigContract.new\nend\n```\n\nThe above example adds a rule to ensure the `email` is valid by matching it against the provided regular expression.\n\nCheck [dry-validation](https:\u002F\u002Fgithub.com\u002Fdry-rb\u002Fdry-validation) for more details.\n\n#### Schema\n\nYou may also specify a schema using [dry-schema](https:\u002F\u002Fgithub.com\u002Fdry-rb\u002Fdry-schema):\n\n```ruby\nConfig.setup do |config|\n  # ...\n  config.schema do\n    optional(:email).maybe(:str?)\n\n    required(:youtube).schema do\n      required(:api_key).filled\n    end\n  end\nend\n```\n\nCheck [dry-schema](https:\u002F\u002Fgithub.com\u002Fdry-rb\u002Fdry-schema) for more details.\n\n### Missing keys\n\nFor an example settings file:\n\n```yaml\nsize: 1\nserver: google.com\n```\n\nYou can test if a value was set for a given key using `key?` and its alias `has_key?`:\n\n```ruby\nSettings.key?(:path)\n# => false\nSettings.key?(:server)\n# => true\n```\n\nBy default, accessing to a missing key returns `nil`:\n\n```ruby\nSettings.key?(:path)\n# => false\nSettings.path\n# => nil\n```\n\nThis is not \"typo-safe\". To solve this problem, you can configure the `fail_on_missing` option:\n\n```ruby\nConfig.setup do |config|\n  config.fail_on_missing = true\n  # ...\nend\n```\n\nSo it will raise a `KeyError` when accessing a non-existing key (similar to `Hash#fetch` behaviour):\n\n```ruby\nSettings.path\n# => raises KeyError: key not found: :path\n```\n\n### Environment variables\n\nSee section below for more details.\n\n## Working with environment variables\n\nTo load environment variables from the `ENV` object, that will override any settings defined in files, set the `use_env` to true in your `config\u002Finitializers\u002Fconfig.rb` file:\n\n```ruby\nConfig.setup do |config|\n  config.const_name = 'Settings'\n  config.use_env = true\nend\n```\n\nNow config would read values from the ENV object to the settings. For the example above it would look for keys starting with `Settings`:\n\n```ruby\nENV['Settings.section.size'] = 1\nENV['Settings.section.server'] = 'google.com'\n```\n\nIt won't work with arrays, though.\n\nIt is considered an error to use environment variables to simultaneously assign a \"flat\" value and a multi-level value to a key.\n\n```ruby\n# Raises an error when settings are loaded\nENV['BACKEND_DATABASE'] = 'development'\nENV['BACKEND_DATABASE_USER'] = 'postgres'\n```\n\nInstead, specify keys of equal depth in the environment variable names:\n\n```ruby\nENV['BACKEND_DATABASE_NAME'] = 'development'\nENV['BACKEND_DATABASE_USER'] = 'postgres'\n```\n\n### Working with Heroku\n\nHeroku uses ENV object to store sensitive settings. You cannot upload such files to Heroku because it's ephemeral filesystem gets recreated from the git sources on each instance refresh. To use config with Heroku just set the `use_env` var to `true` as mentioned above.\n\nTo upload your local values to Heroku you could ran `bundle exec rake config:heroku`.\n\n### Fine-tuning\n\nYou can customize how environment variables are processed:\n\n* `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive)\n* `env_separator` (default: `'.'`)  - what string to use as level separator - default value of `.` works well with   Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using   dots in variable names might not be allowed (eg. Bash)\n* `env_converter` (default: `:downcase`)  - how to process variables names:\n  * `nil` - no change\n  * `:downcase` - convert to lower case\n* `env_parse_values` (default: `true`) - try to parse values to a correct type (`Boolean`, `Integer`, `Float`, `String`)\n\nFor instance, given the following environment:\n\n```bash\nSETTINGS__SECTION__SERVER_SIZE=1\nSETTINGS__SECTION__SERVER=google.com\nSETTINGS__SECTION__SSL_ENABLED=false\n```\n\nAnd the following configuration:\n\n```ruby\nConfig.setup do |config|\n  config.use_env = true\n  config.env_prefix = 'SETTINGS'\n  config.env_separator = '__'\n  config.env_converter = :downcase\n  config.env_parse_values = true\nend\n```\n\nThe following settings will be available:\n\n```ruby\nSettings.section.server_size # => 1\nSettings.section.server # => 'google.com'\nSettings.section.ssl_enabled # => false\n```\n\n### Working with AWS Secrets Manager\n\nIt is possible to parse variables stored in an AWS Secrets Manager Secret as if they were environment variables by using `Config::Sources::EnvSource`.\n\nFor example, the plaintext secret might look like this:\n\n```json\n{\n  \"Settings.foo\": \"hello\",\n  \"Settings.bar\": \"world\",\n}\n```\n\nIn order to load those settings, fetch the settings from AWS Secrets Manager, parse the plaintext as JSON, pass the resulting `Hash` into a new `EnvSource`, load the new source, and reload.\n\n```ruby\n# fetch secrets from AWS\nclient = Aws::SecretsManager::Client.new\nresponse = client.get_secret_value(secret_id: \"#{ENV['ENVIRONMENT']}\u002Fmy_application\")\nsecrets = JSON.parse(response.secret_string)\n\n# load secrets into config\nsecret_source = Config::Sources::EnvSource.new(secrets)\nSettings.add_source!(secret_source)\nSettings.reload!\n```\n\nIn this case, the following settings will be available:\n\n```ruby\nSettings.foo # => \"hello\"\nSettings.bar # => \"world\"\n```\n\nBy default, `EnvSource` will use configuration for `env_prefix`, `env_separator`, `env_converter`, and `env_parse_values`, but any of these can be overridden in the constructor.\n\n```ruby\nsecret_source = Config::Sources::EnvSource.new(secrets,\n                                               prefix: 'MyConfig',\n                                               separator: '__',\n                                               converter: nil,\n                                               parse_values: false)\n```\n\n## Contributing\n\nYou are very warmly welcome to help. Please follow our [contribution guidelines](CONTRIBUTING.md)\n\nAny and all contributions offered in any form, past present or future are understood to be in complete agreement and acceptance with [MIT](LICENSE) license.\n\n### Running specs\n\nSetup\n\n```sh\nbundle install\nbundle exec appraisal install\n```\n\nList defined appraisals:\n\n```sh\nbundle exec appraisal list\n```\n\nRun specs for specific appraisal:\n\n```sh\nbundle exec appraisal rails-6.1 rspec\n```\n\nRun specs for all appraisals:\n\n```sh\nbundle exec appraisal rspec\n```\n\n## Authors\n\n* [Piotr Kuczynski](http:\u002F\u002Fgithub.com\u002Fpkuczynski)\n* [Fred Wu](http:\u002F\u002Fgithub.com\u002Ffredwu)\n* [Jacques Crocker](http:\u002F\u002Fgithub.com\u002Frailsjedi)\n* Inherited from [AppConfig](http:\u002F\u002Fgithub.com\u002Fcjbottaro\u002Fapp_config) by [Christopher J. Bottaro](http:\u002F\u002Fgithub.com\u002Fcjbottaro)\n\n## Contributors\n\n### Code Contributors\n\nThis project exists thanks to all the people who contribute and you are very warmly welcome to help. Please follow our [contribution guidelines](CONTRIBUTING.md).\n\nAny and all contributions offered in any form, past present or future are understood to be in complete agreement and acceptance with the [MIT](LICENSE) license.\n\n[![Contributors](https:\u002F\u002Fopencollective.com\u002Frubyconfig\u002Fcontributors.svg?width=890&button=false)](https:\u002F\u002Fgithub.com\u002Frubyconfig\u002Fconfig\u002Fgraphs\u002Fcontributors)\n\n### Financial Contributors\n\n[Become a backer](https:\u002F\u002Fopencollective.com\u002Frubyconfig#backer) and support us with a small monthly donation to help us continue our activities. Thank you if you already one! 🙏\n\n[![Backers](https:\u002F\u002Fopencollective.com\u002Frubyconfig\u002Fbackers.svg?width=890)](https:\u002F\u002Fopencollective.com\u002Frubyconfig)\n\n#### Sponsors\n\nSupport this project by becoming a [sponsor](https:\u002F\u002Fopencollective.com\u002Frubyconfig#sponsor). Your logo will show up here with a link to your website.\n\n[![Sponsors](https:\u002F\u002Fopencollective.com\u002Frubyconfig\u002Fsponsors.svg?width=890)](https:\u002F\u002Fopencollective.com\u002Frubyconfig)\n\n## License\n\nCopyright (C) Piotr Kuczynski. Released under the [MIT License](LICENSE.md).\n","rubyconfig\u002Fconfig 是一个简化 Ruby 项目多环境配置管理的工具。它支持通过简单的 YAML 文件来定义不同环境下的设置，并且这些文件可以使用 ERB 模板，支持继承和多级设置。此外，它还提供了方便的对象成员访问方式来读取配置信息，使得开发者能够以更直观的方式处理复杂的配置需求。该库适用于 Rails、Sinatra 和 Padrino 等 Ruby 应用框架，特别适合需要根据不同部署环境（如开发、测试、生产）灵活调整参数的应用场景。",2,"2026-06-11 03:15:41","top_language"]