easy_conf 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -15
- data/easy_conf.gemspec +4 -0
- data/lib/easy_conf/app_config.rb +8 -67
- data/lib/easy_conf/configuration.rb +29 -12
- data/lib/easy_conf/errors/config_not_found_error.rb +1 -1
- data/lib/easy_conf/errors/interface_error.rb +3 -0
- data/lib/easy_conf/errors/lookup_name_conflict_error.rb +13 -0
- data/lib/easy_conf/lookup/abstract_lookup.rb +51 -0
- data/lib/easy_conf/lookup/e_vault.rb +59 -0
- data/lib/easy_conf/lookup/env.rb +22 -0
- data/lib/easy_conf/lookup/yaml.rb +67 -0
- data/lib/easy_conf/lookup/zookeeper.rb +63 -0
- data/lib/easy_conf/lookup_visitor.rb +12 -0
- data/lib/easy_conf/version.rb +1 -1
- data/lib/easy_conf.rb +35 -18
- metadata +53 -5
- data/lib/easy_conf/errors/config_file_not_found_error.rb +0 -9
- data/lib/easy_conf/errors/unpermitted_config_error.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c6dd25dd6e8987b0bb0a8138e492e74f2403729
|
4
|
+
data.tar.gz: 5f345c00d9a5a10d7be486fc2a137e79777a0c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ce5669a0e0097fd16d6cce3e187a61195c672a90728cb6d040a034ae3674fbb21af8c5b31917d736d412405f46f5daa7bf6810b7aa68856947df1c725b96a5c
|
7
|
+
data.tar.gz: c2629b30b54cf086d52509ab924098fffe7dda9ac7637d4ca9f492f38f4d13fb07b9efcdbedfb61e41789e0d77acfcf558c133ad134b2c23a1b07927afae59d0
|
data/README.md
CHANGED
@@ -4,7 +4,9 @@ EasyConf, as its name suggest, is a gem for managing application configuration e
|
|
4
4
|
|
5
5
|
You may wonder why I've created this gem. The answer is simple; because convention matters!
|
6
6
|
|
7
|
-
I
|
7
|
+
I've seen lots of applications written by other awesome developers and I noticed that they are managing their configurations either by using config files or via environment variables or even both! As a result of this, in those applications you can see something like `ENV['foo']` and `Rails.application.config` mixed all around the source of the application. What a mess.
|
8
|
+
|
9
|
+
Directly accessing the source of configuration highly couples the way you configure your application with the application logic and if you want to change the way you configure the application you will have to touch the code itself which is bad.
|
8
10
|
|
9
11
|
Beside of this complexity your production environment may have some restrictions you don't have on your own development environment. For example, if you are using Heroku you can't use config files to configure your application. Because you have to untrack config files on your VCS unless you have a good reason to track them. By using EasyConf while you can configure your application with config files also you can use environment variables on your production environment and this will give you a good abstraction on configuration!
|
10
12
|
|
@@ -28,16 +30,14 @@ Or install it yourself as:
|
|
28
30
|
|
29
31
|
#### EasyConf configuration
|
30
32
|
|
31
|
-
EasyConf requires its own configuration to determine
|
33
|
+
EasyConf requires its own configuration to determine the source of the configurations etc. For Rails applications, create a file under config directory which looks like;
|
32
34
|
|
33
35
|
```ruby
|
34
36
|
require 'easy_conf'
|
35
37
|
|
36
38
|
EasyConf.configure do |config|
|
37
|
-
config.
|
38
|
-
config.
|
39
|
-
config.white_list_keys = [:foo]
|
40
|
-
config.environment = :production
|
39
|
+
config.lookups = [EasyConf::Lookup::Env, EasyConf::Lookup::Yaml]
|
40
|
+
config.decoder = Proc.new { |value| value.upcase }
|
41
41
|
end
|
42
42
|
```
|
43
43
|
|
@@ -78,18 +78,18 @@ Or if you want to get your configurations from config files as Hash, you can jus
|
|
78
78
|
EasyConf.to_hash # { "foo" => "bar" }
|
79
79
|
```
|
80
80
|
|
81
|
-
## Configuration
|
82
|
-
|
83
|
-
**config_files:** *Required! List of configuration files to be used.
|
84
|
-
If you don't configure this, EasyConf can read configurations from only environment variables.
|
81
|
+
## Available Configuration Backends
|
85
82
|
|
86
|
-
|
83
|
+
- Environment variables (EasyConf::Lookup::Env)
|
84
|
+
- Yaml files (EasyConf::Lookup::Yaml)
|
85
|
+
- Vault (EasyConf::Lookup::EVault)
|
86
|
+
- Zookeeper (EasyConf::Lookup::Zookeeper)
|
87
87
|
|
88
|
-
|
88
|
+
## Configuration Keys
|
89
89
|
|
90
|
-
**
|
90
|
+
**lookups:** Optional, default is `[EasyConf::Lookup::Env, EasyConf::Lookup::Yaml]`. List of lookups to be used to fetch the configuration. The lookup is basically the source of the configuration which. EasyConf implements `Env`, `YamlL`, `EVault` and `Zookeeper` lookups by default. You can also implement your own lookup, for more information about how to implement a lookup, you may have a look at the source of builtin lookups.
|
91
91
|
|
92
|
-
**
|
92
|
+
**decoder:** Optional. The idea behind of having this key is, having configuration values as Ruby objects. If you set the ENV var FOO as `"--- 1\n...\n"` and set the `decoder` option as `Proc.new { |value| YAML.load(value) }` the return value of EasyConf.app_config.FOO will be `1` as Fixnum instead of String.
|
93
93
|
|
94
94
|
## TIPS
|
95
95
|
|
@@ -141,7 +141,6 @@ If you think storing configuration files at S3 is not good then you can use some
|
|
141
141
|
## TODO
|
142
142
|
|
143
143
|
1. Write tests
|
144
|
-
2. Write adapter for ZooKeeper
|
145
144
|
|
146
145
|
## Contributing
|
147
146
|
|
data/easy_conf.gemspec
CHANGED
@@ -19,7 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency "vault"
|
23
|
+
spec.add_dependency "zk", "~> 1.9"
|
24
|
+
|
22
25
|
spec.add_development_dependency "bundler", "~> 1.11"
|
23
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency "pry"
|
25
29
|
end
|
data/lib/easy_conf/app_config.rb
CHANGED
@@ -1,84 +1,25 @@
|
|
1
1
|
module EasyConf
|
2
2
|
class AppConfig # :nodoc
|
3
3
|
|
4
|
-
MESSAGES = {
|
5
|
-
unpermitted_key: 'Found unpermitted key'.freeze,
|
6
|
-
file_not_found: 'Configuration file not found'.freeze,
|
7
|
-
config_not_found: 'Configuration not found'.freeze,
|
8
|
-
}
|
9
|
-
|
10
|
-
EXCEPTIONS = {
|
11
|
-
unpermitted_key: 'UnpermittedConfigError'.freeze,
|
12
|
-
file_not_found: 'ConfigFileNotFoundError'.freeze,
|
13
|
-
config_not_found: 'ConfigNotFoundError'.freeze,
|
14
|
-
}
|
15
|
-
|
16
4
|
def initialize
|
17
|
-
@
|
5
|
+
@dict = {}
|
18
6
|
end
|
19
7
|
|
20
8
|
def method_missing(meth, *args, &block)
|
21
|
-
|
9
|
+
define_singleton_method(meth) do
|
10
|
+
@dict[meth]
|
11
|
+
end
|
22
12
|
|
23
|
-
|
13
|
+
@dict[meth] = LookupVisitor.visit(meth)
|
24
14
|
end
|
25
15
|
|
26
16
|
def __keys
|
27
|
-
@
|
17
|
+
@dict.keys
|
28
18
|
end
|
29
19
|
|
30
20
|
def __to_hash
|
31
|
-
@
|
21
|
+
@dict.dup
|
32
22
|
end
|
33
23
|
|
34
|
-
private
|
35
|
-
def __configuration
|
36
|
-
EasyConf.configuration
|
37
|
-
end
|
38
|
-
|
39
|
-
def __read_config
|
40
|
-
env = __configuration.environment.to_s
|
41
|
-
|
42
|
-
__configuration.config_files.inject({}) do |conf, config_file|
|
43
|
-
tmp = if File.exists?(config_file)
|
44
|
-
yaml_data = YAML.load_file(config_file)
|
45
|
-
env.blank? ? yaml_data : yaml_data.fetch(env, {})
|
46
|
-
else
|
47
|
-
__notify(:file_not_found, config_file) && {}
|
48
|
-
end
|
49
|
-
conf.merge(tmp)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def __read_from_table(key)
|
54
|
-
if val = @table[key.to_s]
|
55
|
-
define_singleton_method(key) { val }
|
56
|
-
send(key)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def __read_from_env(key)
|
61
|
-
if val = ENV[key.to_s]
|
62
|
-
define_singleton_method(key) { val }
|
63
|
-
send(key)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def __list_check(key)
|
68
|
-
(__configuration.black_list_keys.length > 0 && __configuration.black_list_keys.include?(key)) ||
|
69
|
-
(__configuration.black_list_keys.length == 0 &&
|
70
|
-
(__configuration.white_list_keys.length > 0 && !__configuration.white_list_keys.include?(key)))
|
71
|
-
end
|
72
|
-
|
73
|
-
def __notify(event, obj)
|
74
|
-
message = "#{MESSAGES[event]}: `#{obj}`"
|
75
|
-
|
76
|
-
if __configuration.inform_with == :exception
|
77
|
-
exception_class = "EasyConf::#{EXCEPTIONS[event]}"
|
78
|
-
raise exception_class.constantize.new(message)
|
79
|
-
else
|
80
|
-
puts message
|
81
|
-
end
|
82
|
-
end
|
83
24
|
end
|
84
|
-
end
|
25
|
+
end
|
@@ -1,24 +1,41 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
1
3
|
module EasyConf
|
2
4
|
class Configuration # :nodoc
|
3
|
-
attr_accessor :
|
5
|
+
attr_accessor :decoder
|
6
|
+
attr_reader :lookups
|
4
7
|
|
5
8
|
def initialize
|
6
|
-
@
|
7
|
-
@inform_with = :log
|
8
|
-
@white_list_keys = []
|
9
|
-
@black_list_keys = []
|
9
|
+
@lookups = []
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
@
|
12
|
+
def lookups=(lookups)
|
13
|
+
@lookups = lookups.to_a
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def register_lookup(klass)
|
17
|
+
register_placeholder(klass.placeholder)
|
18
|
+
@lookups << klass
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
-
@
|
21
|
+
def de_register_lookup(klass)
|
22
|
+
@lookups -= [klass]
|
22
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def register_placeholder(placeholder)
|
27
|
+
check_placeholder_conflict!(placeholder)
|
28
|
+
|
29
|
+
instance_variable_set("@#{placeholder}_conf", OpenStruct.new)
|
30
|
+
|
31
|
+
define_singleton_method(placeholder) do
|
32
|
+
instance_variable_get("@#{placeholder}_conf")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_placeholder_conflict!(placeholder)
|
37
|
+
raise LookupNameConflictError.new(placeholder) if self.class.instance_methods(:false).include?(placeholder)
|
38
|
+
end
|
39
|
+
|
23
40
|
end
|
24
|
-
end
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module EasyConf
|
2
|
+
class LookupNameConflictError < RuntimeError
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
message = "`#{name}` placeholder is conflicting with the internal methods " \
|
6
|
+
"of the `EasyConf::Configuration` class. Register lookup with a " \
|
7
|
+
"different name to solve this issue!"
|
8
|
+
|
9
|
+
super(message)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module EasyConf
|
4
|
+
module Lookup
|
5
|
+
class AbstractLookup
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer :placeholder
|
9
|
+
|
10
|
+
def read(key)
|
11
|
+
raise_interface_error!
|
12
|
+
end
|
13
|
+
|
14
|
+
def placeholder
|
15
|
+
@placeholder ||= self.to_s.split('::').last.downcase
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def raise_interface_error!
|
20
|
+
method_name = caller_locations(1, 1)[0].label
|
21
|
+
error_message = "`#{method_name}` method should be implemented in `#{self.name}` class!"
|
22
|
+
|
23
|
+
raise EasyConf::InterfaceError.new(error_message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def commit(raw_value)
|
27
|
+
throw(
|
28
|
+
:config_found,
|
29
|
+
apply_decoding(raw_value) || apply_default_decoding(raw_value) || raw_value
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def apply_decoding(value)
|
34
|
+
if lookup_config && lookup_config.decoder
|
35
|
+
lookup_config.decoder.call(value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def apply_default_decoding(value)
|
40
|
+
EasyConf.configuration.decoder.call(value) if EasyConf.configuration.decoder
|
41
|
+
end
|
42
|
+
|
43
|
+
def lookup_config
|
44
|
+
EasyConf.configuration.send(placeholder)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "vault"
|
2
|
+
|
3
|
+
# Reads configurations from Vault.
|
4
|
+
#
|
5
|
+
# This lookup is NOT registered by default, you can register
|
6
|
+
# it with;
|
7
|
+
#
|
8
|
+
# EasyConf.register_lookup(EasyConf::Lookup::EVault)
|
9
|
+
#
|
10
|
+
# Beside the Vault configuration which has to be done seperately,
|
11
|
+
# the lookup has one mandatory configuration key;
|
12
|
+
#
|
13
|
+
# key_prefix : If you are already familiar with Vault, you may know that the values
|
14
|
+
# are stored in paths like 'secret/foo'. Here the key is foo and the
|
15
|
+
# value of foo is stored at secret engine. The prefix has to be set
|
16
|
+
# by the user depending on the way how they configured and use Vault.
|
17
|
+
#
|
18
|
+
# Configure as following;
|
19
|
+
#
|
20
|
+
# EasyConf.configure do |config|
|
21
|
+
# config.vault.key_prefix = 'secret/foo/bar'
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# Additionally you can set the Vault configurations via ENV like so;
|
25
|
+
#
|
26
|
+
# export VAULT_ADDR=http://127.0.0.1:8200
|
27
|
+
# export VAULT_TOKEN=token
|
28
|
+
# export VAULT_SSL_VERIFY=false
|
29
|
+
module EasyConf
|
30
|
+
module Lookup
|
31
|
+
class EVault < AbstractLookup
|
32
|
+
self.placeholder = :vault
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def read(key)
|
36
|
+
value = read_vault(key)
|
37
|
+
value && commit(value)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def read_vault(key)
|
42
|
+
vault_path = key_path(key)
|
43
|
+
|
44
|
+
secret = Vault.with_retries(Vault::HTTPError) do
|
45
|
+
Vault.logical.read(vault_path)
|
46
|
+
end
|
47
|
+
|
48
|
+
secret && secret.data && secret.data[:value]
|
49
|
+
end
|
50
|
+
|
51
|
+
def key_path(key)
|
52
|
+
"#{lookup_config.key_prefix}/#{key}"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Reads configurations from YAML files.
|
2
|
+
#
|
3
|
+
# This lookup is registered by default, you can de-register
|
4
|
+
# it with;
|
5
|
+
#
|
6
|
+
# EasyConf.de_register_lookup(EasyConf::Lookup::Env)
|
7
|
+
module EasyConf
|
8
|
+
module Lookup
|
9
|
+
class Env < AbstractLookup
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def read(key)
|
13
|
+
value = ENV[key.to_s]
|
14
|
+
value && commit(value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
EasyConf.register_lookup(EasyConf::Lookup::Env)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
# Reads configurations from YAML files.
|
4
|
+
#
|
5
|
+
# This lookup is registered by default, you can de-register
|
6
|
+
# it with;
|
7
|
+
#
|
8
|
+
# EasyConf.de_register_lookup(EasyConf::Lookup::Yaml)
|
9
|
+
#
|
10
|
+
# The lookup has two configuration keys;
|
11
|
+
#
|
12
|
+
# config_files : The list of files that the lookup will be performed against.
|
13
|
+
# scope : If set, the configuration key will be searched in file under
|
14
|
+
# the scope key. Use case of this config is, setting it as app
|
15
|
+
# env so in one file you can have all the configs for all the
|
16
|
+
# environments but the value this module will return will be
|
17
|
+
# the one for that environment.
|
18
|
+
#
|
19
|
+
# Configure as following;
|
20
|
+
#
|
21
|
+
# EasyConf.configure do |config|
|
22
|
+
# config.yaml.config_files = [...]
|
23
|
+
# config.yaml.scope = Rails.env
|
24
|
+
# end
|
25
|
+
module EasyConf
|
26
|
+
module Lookup
|
27
|
+
class Yaml < AbstractLookup
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def read(key)
|
31
|
+
value = dict[key.to_s]
|
32
|
+
!value.nil? && commit(value)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def dict
|
37
|
+
@dict ||= read_config_files
|
38
|
+
end
|
39
|
+
|
40
|
+
def read_config_files
|
41
|
+
config_files.reduce({}) do |memo, config_file|
|
42
|
+
read_config_file(config_file).each { |k, v| memo[k.to_s] = v }
|
43
|
+
|
44
|
+
memo
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def read_config_file(config_file)
|
49
|
+
content = YAML.load_file(config_file)
|
50
|
+
scope ? content[scope] : content
|
51
|
+
end
|
52
|
+
|
53
|
+
def config_files
|
54
|
+
EasyConf.configuration.yaml.config_files.to_a
|
55
|
+
end
|
56
|
+
|
57
|
+
def scope
|
58
|
+
EasyConf.configuration.yaml.scope
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
EasyConf.register_lookup(EasyConf::Lookup::Yaml)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "zk"
|
2
|
+
|
3
|
+
# Reads configurations from Zookeeper.
|
4
|
+
#
|
5
|
+
# This lookup is NOT registered by default, you can register
|
6
|
+
# it with;
|
7
|
+
#
|
8
|
+
# EasyConf.register_lookup(EasyConf::Lookup::Zookeeper)
|
9
|
+
#
|
10
|
+
# Beside the Zookeeper configuration which has to be done seperately,
|
11
|
+
# the lookup has one mandatory configuration key;
|
12
|
+
#
|
13
|
+
# key_prefix : If you are already familiar with Zookeeper, you may know that the values
|
14
|
+
# are stored in paths like 'my_app/foo'. Here the key is foo and the
|
15
|
+
# value of foo is stored at my_app directory. The prefix has to be set
|
16
|
+
# by the user depending on the way how they configured and use Zookeeper.
|
17
|
+
# Note that, leading / is a must. If the configuration is set on root path
|
18
|
+
# you can set `key_prefix` as empty string.
|
19
|
+
#
|
20
|
+
# Configure as following;
|
21
|
+
#
|
22
|
+
# EasyConf.configure do |config|
|
23
|
+
# config.zookeeper.key_prefix = '/my_app/foo'
|
24
|
+
# config.zookeeper.addresses = ['localhost:2181', 'localhost:2182', 'localhost:2183']
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# Additionally you can set the Vault configurations via ENV like so;
|
28
|
+
#
|
29
|
+
# export ZOOKEEPER_ADDR=localhost:2181,localhost:2182,localhost:2183
|
30
|
+
module EasyConf
|
31
|
+
module Lookup
|
32
|
+
class Zookeeper < AbstractLookup
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def read(key)
|
36
|
+
value = read_zookeeper(key)
|
37
|
+
value && commit(value)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def read_zookeeper(key)
|
42
|
+
zookeeper_path = key_path(key)
|
43
|
+
|
44
|
+
client.get(zookeeper_path)[0]
|
45
|
+
rescue ZK::Exceptions::NoNode
|
46
|
+
end
|
47
|
+
|
48
|
+
def client
|
49
|
+
@client ||= ZK.new(zookeeper_address)
|
50
|
+
end
|
51
|
+
|
52
|
+
def zookeeper_address
|
53
|
+
lookup_config.addresses ? lookup_config.addresses.join(',') : ENV['ZOOKEEPER_ADDR']
|
54
|
+
end
|
55
|
+
|
56
|
+
def key_path(key)
|
57
|
+
"#{lookup_config.key_prefix}/#{key}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/easy_conf/version.rb
CHANGED
data/lib/easy_conf.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require "easy_conf/version"
|
2
2
|
require "easy_conf/app_config"
|
3
|
+
require "easy_conf/lookup_visitor"
|
3
4
|
require "easy_conf/configuration"
|
5
|
+
require "easy_conf/errors/interface_error"
|
6
|
+
require "easy_conf/errors/lookup_name_conflict_error"
|
4
7
|
require "easy_conf/errors/config_not_found_error"
|
5
|
-
require "easy_conf/
|
6
|
-
require "easy_conf/errors/config_file_not_found_error"
|
8
|
+
require "easy_conf/lookup/abstract_lookup"
|
7
9
|
|
8
10
|
module EasyConf
|
9
11
|
|
@@ -52,28 +54,38 @@ module EasyConf
|
|
52
54
|
app_config.__to_hash
|
53
55
|
end
|
54
56
|
|
57
|
+
# Registers a new lookup class to the lookup list.
|
58
|
+
#
|
59
|
+
# Example:
|
60
|
+
#
|
61
|
+
# EasyConf.register_lookup(EasyConf::Lookup::Env)
|
62
|
+
def register_lookup(klass)
|
63
|
+
configuration.register_lookup(klass)
|
64
|
+
end
|
65
|
+
|
66
|
+
# De-registers the lookup class from the lookup list.
|
67
|
+
#
|
68
|
+
# Example:
|
69
|
+
#
|
70
|
+
# EasyConf.de_register_lookup(EasyConf::Lookup::Env)
|
71
|
+
def de_register_lookup(klass)
|
72
|
+
configuration.de_register_lookup(klass)
|
73
|
+
end
|
74
|
+
|
55
75
|
# Configures the EasyConf gem for the following keys;
|
56
76
|
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
# accessible through EasyConf!
|
64
|
-
# black_list_keys : Optional! List of config keys to be ignored.
|
65
|
-
# If this configuration is set, config keys
|
66
|
-
# which are in this list won't be accessible
|
67
|
-
# through EasyConf!
|
68
|
-
# environment : Optional. Specifies environment scope. For Rails
|
69
|
-
# applications, the value is same with Rails.
|
77
|
+
# lookups : Optional. An array of lookup classes. By default, EasyConf uses
|
78
|
+
# ENV and YAML lookups.
|
79
|
+
# decoder : Optional. If you are encoding your config values before saving,
|
80
|
+
# you can let EasyConf decode them automatically by setting this
|
81
|
+
# with a `Proc`. This is usefull if you don't want to handle type
|
82
|
+
# casting in your code.
|
70
83
|
#
|
71
84
|
# Example:
|
72
85
|
#
|
73
86
|
# EasyConf.configure do |config|
|
74
|
-
# config.
|
75
|
-
# config.
|
76
|
-
# config.black_list_keys = ['black_key', ...]
|
87
|
+
# config.lookups = [EasyConf::Lookup::Env, EasyConf::Lookup::Yaml]
|
88
|
+
# config.decoder = Proc.new { |value| YAML.load(value) }
|
77
89
|
# end
|
78
90
|
def configure
|
79
91
|
yield(configuration)
|
@@ -86,3 +98,8 @@ module EasyConf
|
|
86
98
|
end
|
87
99
|
|
88
100
|
end
|
101
|
+
|
102
|
+
require "easy_conf/lookup/env"
|
103
|
+
require "easy_conf/lookup/yaml"
|
104
|
+
require "easy_conf/lookup/e_vault"
|
105
|
+
require "easy_conf/lookup/zookeeper"
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_conf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Emin İNAÇ
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: vault
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +80,20 @@ dependencies:
|
|
52
80
|
- - "~>"
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
55
97
|
description: EasyConf is a gem for reading configurations either from yaml files or
|
56
98
|
from environment variables. With this gem you don't worry about where were your
|
57
99
|
configurations.
|
@@ -74,9 +116,15 @@ files:
|
|
74
116
|
- lib/easy_conf.rb
|
75
117
|
- lib/easy_conf/app_config.rb
|
76
118
|
- lib/easy_conf/configuration.rb
|
77
|
-
- lib/easy_conf/errors/config_file_not_found_error.rb
|
78
119
|
- lib/easy_conf/errors/config_not_found_error.rb
|
79
|
-
- lib/easy_conf/errors/
|
120
|
+
- lib/easy_conf/errors/interface_error.rb
|
121
|
+
- lib/easy_conf/errors/lookup_name_conflict_error.rb
|
122
|
+
- lib/easy_conf/lookup/abstract_lookup.rb
|
123
|
+
- lib/easy_conf/lookup/e_vault.rb
|
124
|
+
- lib/easy_conf/lookup/env.rb
|
125
|
+
- lib/easy_conf/lookup/yaml.rb
|
126
|
+
- lib/easy_conf/lookup/zookeeper.rb
|
127
|
+
- lib/easy_conf/lookup_visitor.rb
|
80
128
|
- lib/easy_conf/version.rb
|
81
129
|
homepage: http://github.com/meinac/easy_conf
|
82
130
|
licenses:
|
@@ -98,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
146
|
version: '0'
|
99
147
|
requirements: []
|
100
148
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.6.8
|
102
150
|
signing_key:
|
103
151
|
specification_version: 4
|
104
152
|
summary: Easily manage your app configurations.
|