Module: EasyConf

Defined in:
lib/easy_conf/lookup/env.rb,
lib/easy_conf.rb,
lib/easy_conf/version.rb,
lib/easy_conf/app_config.rb,
lib/easy_conf/lookup/yaml.rb,
lib/easy_conf/configuration.rb,
lib/easy_conf/lookup/e_vault.rb,
lib/easy_conf/lookup_visitor.rb,
lib/easy_conf/lookup/zookeeper.rb,
lib/easy_conf/errors/interface_error.rb,
lib/easy_conf/lookup/abstract_lookup.rb,
lib/easy_conf/errors/config_not_found_error.rb,
lib/easy_conf/errors/lookup_name_conflict_error.rb

Overview

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

Defined Under Namespace

Modules: Lookup Classes: AppConfig, ConfigNotFoundError, Configuration, InterfaceError, LookupNameConflictError, LookupVisitor

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.app_configObject

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"


25
26
27
# File 'lib/easy_conf.rb', line 25

def app_config
  @config ||= AppConfig.new
end

.configurationObject

:nodoc



95
96
97
# File 'lib/easy_conf.rb', line 95

def configuration # :nodoc
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

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

Yields:



90
91
92
93
# File 'lib/easy_conf.rb', line 90

def configure
  yield(configuration)
  app_config # initialize config
end

.de_register_lookup(klass) ⇒ Object

De-registers the lookup class from the lookup list.

Example:

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


71
72
73
# File 'lib/easy_conf.rb', line 71

def de_register_lookup(klass)
  configuration.de_register_lookup(klass)
end

.keysObject

Read Application config keys

Example:

EasyConf.keys # => [:foo, :bar, ...]


44
45
46
# File 'lib/easy_conf.rb', line 44

def keys
  app_config.__keys
end

.read(key) ⇒ Object Also known as: get

Read Application configuration by sending key as argument.

Example:

EasyConf.read(:access_key) # => "some_key"


34
35
36
# File 'lib/easy_conf.rb', line 34

def read(key)
  app_config.send(key.to_s)
end

.register_lookup(klass) ⇒ Object

Registers a new lookup class to the lookup list.

Example:

EasyConf.register_lookup(EasyConf::Lookup::Env)


62
63
64
# File 'lib/easy_conf.rb', line 62

def register_lookup(klass)
  configuration.register_lookup(klass)
end

.to_hashObject

Get application configs as Hash

Example:

EasyConf.to_hash # => { foo: 'bar', ... }


53
54
55
# File 'lib/easy_conf.rb', line 53

def to_hash
  app_config.__to_hash
end