confg 2.0.0.rc1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -22
- data/lib/confg/configuration.rb +11 -7
- data/lib/confg/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d70e2bf601f771c6cc956dab4f21ca2afed56dcdf7159b24e5f17dfa4a8937b
|
4
|
+
data.tar.gz: 4c710349770ca65473e363e949f2f27c071ca0d214dff3d3c509806c55b4cb9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34a799c1d347f3dadc3030e526b14a964753810d663b76107383145891943592254e886fbe5a53b527dbec6cd08676e572513c0d8fa9e9f76818e7d2d52608a5
|
7
|
+
data.tar.gz: cfda628b0bcfa7fffb1bed93cf987241bfebddff79f2c9ddc6d37fa494f877a334ddfb276e6a7e36f922a187ef110c168c564c5f585151b2391536832447cf42
|
data/README.md
CHANGED
@@ -1,33 +1,32 @@
|
|
1
|
-
#
|
1
|
+
# Confg
|
2
2
|
|
3
|
-
|
3
|
+
Provides a utility for loading and managing configurations for your ruby project.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
Set specific keys:
|
8
|
+
|
9
|
+
Confg.configure do |c|
|
10
|
+
c.foo_setting = 100
|
11
|
+
c.bar_setting = "yes"
|
10
12
|
end
|
11
13
|
|
12
|
-
|
14
|
+
Supports nesting:
|
13
15
|
|
14
|
-
|
16
|
+
Confg.configure do |c|
|
15
17
|
c.api_keys do |a|
|
16
|
-
a.
|
18
|
+
a.google = 'xyz'
|
17
19
|
a.mixpanel = 'abc'
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
|
23
|
+
Load a yaml file:
|
22
24
|
|
23
|
-
|
24
|
-
c.load_yaml
|
25
|
-
c.load_yaml :core
|
26
|
-
c.load_yaml '/path/to/some.yml', :something
|
25
|
+
Confg.configure do |c|
|
26
|
+
c.load_yaml "/path/to/file.yml"
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
Yaml files can be namespaced by environment as well. Oh, and they can have ERB:
|
29
|
+
Yaml files can be namespaced by environment and contain ERB.
|
31
30
|
|
32
31
|
---
|
33
32
|
development:
|
@@ -35,11 +34,21 @@ Yaml files can be namespaced by environment as well. Oh, and they can have ERB:
|
|
35
34
|
staging:
|
36
35
|
thing: 'set value'
|
37
36
|
|
38
|
-
|
37
|
+
Use the values:
|
38
|
+
|
39
|
+
Confg.foo_setting
|
40
|
+
#=> 100
|
41
|
+
|
42
|
+
Confg.api_keys
|
43
|
+
#=> #<Confg::Configuration { "google" => "xyz", "mixpanel" => "abc" }>
|
44
|
+
|
45
|
+
Confg.api_keys.google # => "xyz"'
|
46
|
+
|
47
|
+
Confg.api_keys.to_h
|
48
|
+
#=> { "google" => "xyz", "mixpanel" => "abc" }
|
49
|
+
|
50
|
+
Confg.missing_key
|
51
|
+
#=> raises KeyError
|
39
52
|
|
40
|
-
Conf
|
41
|
-
|
42
|
-
Conf.api_keys
|
43
|
-
# => #<Config::Configuration:0x007f9655e5ba58 @attributes={"google_places"=>"xyz", "mixpanel"=>"abc"} >
|
44
|
-
Conf.api_keys.google_places
|
45
|
-
# => 'xyz'
|
53
|
+
Conf[:missing_key]
|
54
|
+
#=> nil
|
data/lib/confg/configuration.rb
CHANGED
@@ -14,6 +14,10 @@ module Confg
|
|
14
14
|
super({})
|
15
15
|
end
|
16
16
|
|
17
|
+
def inspect
|
18
|
+
"#<#{self.class.name} #{__getobj__.inspect}>"
|
19
|
+
end
|
20
|
+
|
17
21
|
def tmp(key, value)
|
18
22
|
initial = get(key)
|
19
23
|
set(key, value)
|
@@ -36,18 +40,18 @@ module Confg
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def get(key)
|
39
|
-
|
43
|
+
fetch(key) { nil }
|
40
44
|
end
|
41
45
|
alias [] get
|
42
46
|
|
43
|
-
def
|
44
|
-
__getobj__.fetch(key.to_s)
|
47
|
+
def fetch(key, &block)
|
48
|
+
__getobj__.fetch(key.to_s, &block)
|
45
49
|
end
|
46
50
|
|
47
51
|
def set(key, value = nil)
|
48
52
|
__getobj__[key.to_s] = case value
|
49
53
|
when ::Hash
|
50
|
-
|
54
|
+
open_block(key) do |child|
|
51
55
|
value.each_pair do |k, v|
|
52
56
|
child.set(k, v)
|
53
57
|
end
|
@@ -99,9 +103,9 @@ module Confg
|
|
99
103
|
elsif key.end_with?("=") && !args.empty?
|
100
104
|
set(key[0...-1], args[0])
|
101
105
|
elsif block_given?
|
102
|
-
|
106
|
+
open_block(key, &block)
|
103
107
|
else
|
104
|
-
|
108
|
+
fetch(key)
|
105
109
|
end
|
106
110
|
end
|
107
111
|
|
@@ -111,7 +115,7 @@ module Confg
|
|
111
115
|
|
112
116
|
protected
|
113
117
|
|
114
|
-
def
|
118
|
+
def open_block(key)
|
115
119
|
inner = get(key) || spawn_child
|
116
120
|
yield(inner)
|
117
121
|
set(key, inner)
|
data/lib/confg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubygems_version: 3.0.3
|
107
107
|
signing_key:
|