Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/redding/much-config
Configuration for Ruby objects.
https://github.com/redding/much-config
Last synced: about 9 hours ago
JSON representation
Configuration for Ruby objects.
- Host: GitHub
- URL: https://github.com/redding/much-config
- Owner: redding
- License: mit
- Created: 2021-06-22T13:48:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-05T15:13:41.000Z (over 2 years ago)
- Last Synced: 2024-08-09T09:38:53.802Z (3 months ago)
- Language: Ruby
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MuchConfig
Configuration for Ruby objects.
## Usage
Mixin MuchConfig in your e.g. `MyClass` Ruby object. Call the `add_config` DSL method and define `MyClass::Config`:
```ruby
module MyClass
include MuchConfigadd_config
def self.value1
config.value1
endclass Config
attr_accessor :value1def initialize
@value1 = "default value for `value1`"
end
end
end
```Configure MyClass using the MuchConfig API:
```ruby
MyClass.config.value1 = "a custom value"# OR
MyClass.configure do |config|
config.value1 = "a custom value"
end
```### Define multiple named configs
You can define multiple named configs, e.g.:
```ruby
module MyClass
include MuchConfigadd_config :values
add_config :settingsdef self.value1
values_config.value1
enddef self.setting1
settings_config.setting1
endclass ValuesConfig
attr_accessor :value1def initialize
@value1 = "default value for `value1`"
end
endclass SettingsConfig
attr_accessor :setting1def initialize
@setting1 = "default value for `setting1`"
end
end
end
```Configure using the MuchConfig API:
```ruby
MyClass.values_config.value1 = "a custom value"
MyClass.settings_config.setting1 = "a custom value"# OR
MyClass.configure_values do |config|
config.value1 = "a custom value"
end
MyClass.configure_settings do |config|
config.setting1 = "a custom value"
end
```## Installation
Add this line to your application's Gemfile:
gem "much-config"
And then execute:
$ bundle
Or install it yourself as:
$ gem install much-config
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am "Added some feature"`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request