module EasyConf

Reads configurations from Vault.

This lookup is NOT registered by default, you can register it with;

EasyConf.register_lookup(EasyConf::Lookup::EVault)

Beside the Vault configuration which has to be done seperately, the lookup has one mandatory configuration key;

key_prefix : If you are already familiar with Vault, you may know that the values
             are stored in paths like 'secret/foo'. Here the key is foo and the
             value of foo is stored at secret engine. The prefix has to be set
             by the user depending on the way how they configured and use Vault.

Configure as following;

EasyConf.configure do |config|

config.vault.key_prefix = 'secret/foo/bar'

end

Additionally you can set the Vault configurations via ENV like so;

export VAULT_ADDR=http://127.0.0.1:8200
export VAULT_TOKEN=token
export VAULT_SSL_VERIFY=false

Reads configurations from YAML files.

This lookup is registered by default, you can de-register it with;

EasyConf.de_register_lookup(EasyConf::Lookup::Env)

Reads configurations from YAML files.

This lookup is registered by default, you can de-register it with;

EasyConf.de_register_lookup(EasyConf::Lookup::Yaml)

The lookup has two configuration keys;

config_files : The list of files that the lookup will be performed against.
scope        : If set, the configuration key will be searched in file under
               the scope key. Use case of this config is, setting it as app
               env so in one file you can have all the configs for all the
               environments but the value this module will return will be
               the one for that environment.

Configure as following;

EasyConf.configure do |config|

config.yaml.config_files = [...]
config.yaml.scope = Rails.env

end

Reads configurations from Zookeeper.

This lookup is NOT registered by default, you can register it with;

EasyConf.register_lookup(EasyConf::Lookup::Zookeeper)

Beside the Zookeeper configuration which has to be done seperately, the lookup has one mandatory configuration key;

key_prefix : If you are already familiar with Zookeeper, you may know that the values
             are stored in paths like 'my_app/foo'. Here the key is foo and the
             value of foo is stored at my_app directory. The prefix has to be set
             by the user depending on the way how they configured and use Zookeeper.
             Note that, leading / is a must. If the configuration is set on root path
             you can set `key_prefix` as empty string.

Configure as following;

EasyConf.configure do |config|

config.zookeeper.key_prefix = '/my_app/foo'
config.zookeeper.addresses = ['localhost:2181', 'localhost:2182', 'localhost:2183']

end

Additionally you can set the Vault configurations via ENV like so;

export ZOOKEEPER_ADDR=localhost:2181,localhost:2182,localhost:2183

Constants

VERSION

Public Class Methods

app_config() click to toggle source

Returns all configurations of your applications.

Example:

EasyConf.app_config # => <EasyConf::AppConfig>

You can access configurations of your application by method call with configuration name.

Example:

EasyConf.app_config.access_key # => "some_key"
# File lib/easy_conf.rb, line 25
def app_config
  @config ||= AppConfig.new
end
configuration() click to toggle source
# File lib/easy_conf.rb, line 95
def configuration # :nodoc
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source

Configures the EasyConf gem for the following keys;

lookups : Optional. An array of lookup classes. By default, EasyConf uses

ENV and YAML lookups.

decoder : Optional. If you are encoding your config values before saving,

you can let EasyConf decode them automatically by setting this
with a `Proc`. This is usefull if you don't want to handle type
casting in your code.

Example:

EasyConf.configure do |config|
  config.lookups = [EasyConf::Lookup::Env, EasyConf::Lookup::Yaml]
  config.decoder = Proc.new { |value| YAML.load(value) }
end
# File lib/easy_conf.rb, line 90
def configure
  yield(configuration)
  app_config # initialize config
end
de_register_lookup(klass) click to toggle source

De-registers the lookup class from the lookup list.

Example:

EasyConf.de_register_lookup(EasyConf::Lookup::Env)
# File lib/easy_conf.rb, line 71
def de_register_lookup(klass)
  configuration.de_register_lookup(klass)
end
get(key)
Alias for: read
keys() click to toggle source

Read Application config keys

Example:

EasyConf.keys # => [:foo, :bar, ...]
# File lib/easy_conf.rb, line 44
def keys
  app_config.__keys
end
read(key) click to toggle source

Read Application configuration by sending key as argument.

Example:

EasyConf.read(:access_key) # => "some_key"
# File lib/easy_conf.rb, line 34
def read(key)
  app_config.send(key.to_s)
end
Also aliased as: get
register_lookup(klass) click to toggle source

Registers a new lookup class to the lookup list.

Example:

EasyConf.register_lookup(EasyConf::Lookup::Env)
# File lib/easy_conf.rb, line 62
def register_lookup(klass)
  configuration.register_lookup(klass)
end
to_hash() click to toggle source

Get application configs as Hash

Example:

EasyConf.to_hash # => { foo: 'bar', ... }
# File lib/easy_conf.rb, line 53
def to_hash
  app_config.__to_hash
end