Module: EasyConf

Defined in:
lib/easy_conf.rb,
lib/easy_conf/version.rb,
lib/easy_conf/app_config.rb,
lib/easy_conf/configuration.rb,
lib/easy_conf/errors/config_not_found_error.rb,
lib/easy_conf/errors/unpermitted_config_error.rb,
lib/easy_conf/errors/config_file_not_found_error.rb

Defined Under Namespace

Classes: AppConfig, ConfigFileNotFoundError, ConfigNotFoundError, Configuration, UnpermittedConfigError

Constant Summary collapse

VERSION =
"0.2.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"


23
24
25
# File 'lib/easy_conf.rb', line 23

def app_config
  @config ||= AppConfig.new
end

.configurationObject

:nodoc



83
84
85
# File 'lib/easy_conf.rb', line 83

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

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

Configures the EasyConf gem for the following keys;

config_files : Required! List of configuration files to be used. inform_with : Optional. Information method used in case of error.

Whether sliently puts log or raises exception.

white_list_keys : Optional. List of config keys to be used.

If this configuration is set, config keys
which are not in this list won't be
accessible through EasyConf!

black_list_keys : Optional! List of config keys to be ignored.

If this configuration is set, config keys
which are in this list won't be accessible
through EasyConf!

environment : Optional. Specifies environment scope. For Rails

applications, the value is same with Rails.

Example:

EasyConf.configure do |config|
  config.config_files    = [config.yml]
  config.white_list_keys = ['access_key', 'secret_key', ...]
  config.black_list_keys = ['black_key', ...]
end

Yields:



78
79
80
81
# File 'lib/easy_conf.rb', line 78

def configure
  yield(configuration)
  app_config # initialize config
end

.keysObject

Read Application config keys

Example:

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


42
43
44
# File 'lib/easy_conf.rb', line 42

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"


32
33
34
# File 'lib/easy_conf.rb', line 32

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

.to_hashObject

Get application configs as Hash

Example:

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


51
52
53
# File 'lib/easy_conf.rb', line 51

def to_hash
  app_config.__to_hash
end