Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yujideveloper/settings_cabinet
A simple settings solution with ERB-enabled YAML file
https://github.com/yujideveloper/settings_cabinet
configuration configuration-management gem rails ruby ruby-gem ruby-on-rails settings-management sinatra
Last synced: 27 days ago
JSON representation
A simple settings solution with ERB-enabled YAML file
- Host: GitHub
- URL: https://github.com/yujideveloper/settings_cabinet
- Owner: yujideveloper
- License: mit
- Created: 2022-04-23T14:21:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-23T02:38:18.000Z (5 months ago)
- Last Synced: 2024-10-22T22:37:53.233Z (2 months ago)
- Topics: configuration, configuration-management, gem, rails, ruby, ruby-gem, ruby-on-rails, settings-management, sinatra
- Language: Ruby
- Homepage:
- Size: 24.4 KB
- Stars: 10
- Watchers: 2
- Forks: 3
- 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
# SettingsCabinet
[![Gem Version](https://badge.fury.io/rb/settings_cabinet.svg)](https://badge.fury.io/rb/settings_cabinet)
[![Build](https://github.com/yujideveloper/settings_cabinet/actions/workflows/main.yml/badge.svg)](https://github.com/yujideveloper/settings_cabinet/actions/workflows/main.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/9b3e8a9816ade4c40398/maintainability)](https://codeclimate.com/github/yujideveloper/settings_cabinet/maintainability)SettingsCabinet is a simple settings solution with ERB-enabled YAML file like [settingslogic](https://github.com/settingslogic/settingslogic).
## Installation
Add this line to your application's Gemfile:
```ruby
gem "settings_cabinet"
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install settings_cabinet
## Usage
DSL is very similar to settingslogic.
```ruby
class Settings < SettingsCabinet::Base
using SettingsCabinet::DSLsource Rails.root.join("config", "settings.yml")
namespace Rails.env
end
```| Name | Type | Description | Default | Optional |
|--|--|--|--|--|
| `source` | String | Path of settings file. | - | No |
| `namespace` | String | Using a namespace allows you to change your configuration depending on your environment. e.g. `Rails.env` | `nil` | Yes |
| `permitted_classes` | Array of Class | Arbitrary classes can be allowed by adding those classes to the allowlist. e.g. `[Date, Time]` | `[]` | Yes |```yaml
# config/settings.yml
defaults: &defaults
foo:
bar: nested setting
baz: <%= 3 * 3 %>
quz: 24development:
<<: *defaults
quz: 48test:
<<: *defaultsproduction:
<<: *defaults
```Accessors are defined in the same way as settingslogic, but writers do not.
```ruby
Settings.foo.bar #=> "nested setting"
Settings[:baz] #=> 9
```You can explicitly load all your settings, if needed.
```ruby
# e.g. config/initializers/settings.rb
using SettingsCabinet::Control
Settings.load!
```
or
```ruby
class Settings < SettingsCabinet::Base
using SettingsCabinet::DSL
using SettingsCabinet::Controlsource Rails.root.join("config", "settings.yml")
namespace Rails.envload!
end
```## Development
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/yujideveloper/settings_cabinet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yujideveloper/settings_cabinet/blob/main/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the SettingsCabinet project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yujideveloper/settings_cabinet/blob/main/CODE_OF_CONDUCT.md).