Skip to content

rezwyi/elasticonf

Repository files navigation

Elasticonf Build Status Dependency Status Coverage Status


Powerfull and flexible application config solution worked in any ruby program. No clases definition, no dependencies. It just works!

Prerequisites

You need to have Ruby 2.0 or higher installed on your system.

Installation

First add the following lines to your application Gemfile:

gem 'elasticonf', '~> 1.1.5'

Then run bundle install to update your's gems bundle.

Setup and usage

For basic setup you must pass a block to Elasticonf.configure method and call Elasticonf.load!.

To load settings from the file some/path/settings.yml and define Settings constant, you need to run the following code:

require 'elasticonf'

Elasticonf.configure do |config|
  config.config_root = 'some/path'
end

Elasticonf.load!
puts Settings.some_key # will print some value

To load settings from the file some/path/config.yml and define Config constant, you need:

require 'elasticonf'

Elasticonf.configure do |config|
  config.config_root = 'some/path'
  config.config_file = 'config'
  config.constant_name = 'Config'
end

Elasticonf.load!
puts Config.some_key # will print some value

There is also support for multi environment. To do this change the value of the config.env (the default is 'development').

Elasticonf supports the following priorities of files (the priority decreases from top to bottom). For the default configuration:

  1. #{Elasticonf.config_root}/settings.local.yml
  2. #{Elasticonf.config_root}/settings/development.yml
  3. #{Elasticonf.config_root}/settings.yml

Sometimes there can be a situation when the constant defined Elasticonf already exists. In this case, exception will raise and method execution will stop. To change this behavior you need to set config.raise_if_already_initialized_constant to false. Take a look:

require 'elasticonf'

Settings = "I'm predefined constant!"

Elasticonf.configure do |config|
  config.config_root = 'some/path'
end

Elasticonf.load! # will raise RuntimeError "Cannot set constant Settings because it is already initialized"

However, this code is okay:

require 'elasticonf'

Settings = "I'm predefined constant!"

Elasticonf.configure do |config|
  config.config_root = 'some/path'
  config.raise_if_already_initialized_constant = false
end

Elasticonf.load! # will not raise any error
puts Settings.some_key # will print some value

Documentation

Run this commands in terminal:

  1. cd path/to/elasticonf/repo
  2. bin/yard server
  3. Go to http://localhost:8808 (by default) in your favorite browser

Testing

Run this commands in terminal:

  1. cd some/path
  2. git clone [email protected]:rezwyi/elasticonf.git
  3. cd elasticonf/
  4. bundle install
  5. bin/rake

Versioning

Elasticonf uses RubyGems Rational Versioning Policy.

Copyright

See LICENSE file.

About

Powerfull and flexible application config solution worked in any ruby program

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages