Skip to content

virtuozzo/info_hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InfoHub

Gem Version

This gem delivers a simple DSL to read data from YAML files. It might be useful for storing some basic knowledge around the application.

Installation

Add the following code to your Gemfile and run bundle install

# Gemfile
gem 'info_hub'

and run bundle install

Create a new file which includes all syste-wide constants:

# config/info_hub.yml
percentage:
    min: 1
    max: 100

Then add path to that file to InfoHub paths (in config/initializers/info_hub.rb)

# config/initializers/info_hub.rb
InfoHub.info_hub_file_paths << File.expand_path('../info_hub.yml', __dir__)

InfoHub.finalize!

Before finalize! execution, you may add as many .yml files as you need. All of them will be deeply merged in the order they were added.

Usage

Now anywhere in you code you can:

InfoHub[:percentage] # => { min: 1, max: 100 }
# or the equivalent
InfoHub.fetch(:percentage) # => { min: 1, max: 100 }

You may also get some internal values:

# Similar to `dig` in ruby 2.3
InfoHub.get(:percentage, :min) # => 1
InfoHub.get(:percentage, :max) # => 100

Licence

See LICENSE file.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/virtuozzo/info_hub.