https://github.com/mockdeep/configurator
https://github.com/mockdeep/configurator
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mockdeep/configurator
- Owner: mockdeep
- License: mit
- Created: 2016-11-13T18:42:41.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2020-10-03T03:41:02.000Z (over 5 years ago)
- Last Synced: 2025-03-25T12:12:53.029Z (about 1 year ago)
- Language: Ruby
- Size: 225 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: License.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
`Configurator` allows you to easily create configuration classes. Simply
`include Configurator` and specify the options you want to be available via
`config`.
## Defining a configuration class
```ruby
require 'configurator'
module MyGem
class Configuration
include Configurator
config :name
config :age
end
end
```
## Accessing your configuration
```ruby
config = MyGem::Configuration.new
config.name = 'Matsumoto'
config.age = 18
config.name # => 'Matsumoto'
```
## Setting configuration options
`Configurator` loads configuration options from three locations automatically.
In order of precedence, lowest to highest:
1. It first tries to infer a default configuration path based on where it is
included from. From your library root directory, you can add a
`config/default.yml`:
```
my_gem
├── config
│ └── default.yml
└── lib
└── my_gem
└── configuration.rb
```
2. It then looks in the home directory of the user for a dot config file named
the same as the library, e.g.: `~/.my_gem.yml`. Any options in this file will
supercede what is defined in the library `config/defaults.yml`.
3. Finally, `Configurator` looks in the current execution directory for a dot
config file with the name of the library: `./.my_gem.yml`. The options here
take precedence over both the `config/default.yml` and home directory
`.my_gem.yml`.
If any options loaded from these config files are not specified in your config
class, an error will be thrown listing the invalid keys.