Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eiskrenkov/open_config
Building deep OpenStructs from configuration files
https://github.com/eiskrenkov/open_config
config configuration gem json ruby rubygems yaml
Last synced: about 1 month ago
JSON representation
Building deep OpenStructs from configuration files
- Host: GitHub
- URL: https://github.com/eiskrenkov/open_config
- Owner: eiskrenkov
- License: mit
- Created: 2021-06-28T21:17:53.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-15T23:41:58.000Z (about 2 years ago)
- Last Synced: 2024-11-10T12:49:23.073Z (3 months ago)
- Topics: config, configuration, gem, json, ruby, rubygems, yaml
- Language: Ruby
- Homepage: https://rubygems.org/gems/open_config
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/rb/open_config)
[](https://github.com/eiskrenkov/open_config/actions/workflows/rspec.yml)# OpenConfig
Ruby gem, that allows you to build deep OpenStructs from your YAML or JSON configuration files## Installation
Add `open_config` to the project's `Gemfile`:```ruby
gem 'open_config', '~> 2.0'
```or as a dependency in your gem's `.gemspec` file
```ruby
Gem::Specification.new do |spec|
# ...
spec.add_dependency 'open_config', '~> 2.0'
# ...
end
```### Supported Ruby versions
- **MRI** >= 2.4
- **JRuby** >= 9.2## Usage
Imagine, you have file, called `configuration.yml` in your project's config folder:```yaml
ruby: <%= 2 + 2 * 2 %>
node:
string: Some String
integer: 123
float: 1.23
boolean: false
nested_node:
array:
- First Element
- Second Element
```You can create OpenConfig instance, and access configuration keys using all advantages of Ruby's `OpenStruct`
```ruby
> config = OpenConfig::YAML.new('configuration.yml')
=> #>>> config.ruby
=> 6> config.node
=> #>> config.node['string']
=> "Some String"> config.node[:boolean]
=> false> config.dig(:node, :string)
=> "Some String"> config.fetch(:foobar, 123)
=> 123> config.fetch(:foobar) # => Exception in `fetch': key not found: :foobar (KeyError)
> config.foobar # => Exception in `method_missing': undefined method `foobar' for #
```Same thing will work with `configuration.json`, just use `OpenConfig::JSON` instead
## Contributing
Bug reports and pull requests are welcome on GitHub at [https://github.com/eiskrenkov/open_config](https://github.com/eiskrenkov/open_config)
## License
OpenConfig is released under [MIT License](http://opensource.org/licenses/MIT)