DotHash
A very efficient gem that lets you use hashes as object properties. It is almost as fast as a plain Hash
since it's complexity is also linear, O(n) # where N is the number of nested parents of the given property
.
Installation
Add this line to your application's Gemfile:
gem 'dot_hash'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dot_hash
Usage
You can convert and hash to DotHash's properties.
some_hash = {size: {height: 100, width: 500}, "color" => "red"}
properties = DotHash.load(some_hash)
properties.size.height
properties.color
properties[:color]
properties["color"]
You can use DotHash::Settings to manage all configs of your app it can load yml, json with or without ERB code embeded.
class Settings < DotHash::Settings
load(
'path/to/some/settings.json',
'path/to/settings-directory/',
{something: 'Some Value'}
)
end
Settings.something
Settings.other.stuff.from_yml_settings
swagger = Settings.new Rails.root.join('config', 'my-swagger.yml')
swagger.info.title
DotHash supports Rails and is very easy to manage fancy settings with it.
class Settings < DotHash::Settings
load(
Rails.root.join('config', 'settings.yml'),
Rails.root.join('package.json'),
*Dir(Rails.root.join('config', 'settings', '*.yml')),
Rails.root.join('config', 'settings', Rails.env),
Rails.root.join('config', 'settings.local.yml')
)
end
Check the tests for more details.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request