palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

Default environmental key #93

Closed skryukov closed 2 years ago

skryukov commented 2 years ago

What is the purpose of this pull request?

This PR adds an ability to set default key for environmental YAML files.

To provide default values we can use YAML anchors, but they do not deep-merge settings, so this PR provides a way to define a special top-level key for default values like this:

config.anyway_config.default_environmental_key = "default"

After that, Anyway Config will start reading settings under the "default" key and then merge environmental settings into them.

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

Is there anything you'd like reviewers to focus on?

In this implementation, a file with only the default key is considered environmental:

default:
  server: # This values will be loaded in all environments by default
    host: localhost
    port: 3002

Checklist

palkan commented 2 years ago

Thanks 👍