confg 2.0.0.rc1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50b51215735b3ac4f8caedb04e36ae28176bb1bd6e7c14c2e3cdced3e7480a1e
4
- data.tar.gz: 95b45d10ab8cb6751afd546d28f4fa76d48e56c4e2746489c5a91cb8dcfcba07
3
+ metadata.gz: 7d70e2bf601f771c6cc956dab4f21ca2afed56dcdf7159b24e5f17dfa4a8937b
4
+ data.tar.gz: 4c710349770ca65473e363e949f2f27c071ca0d214dff3d3c509806c55b4cb9b
5
5
  SHA512:
6
- metadata.gz: c94266338ff570a78f1db7e736be6264f89658d3c96711c78871a34a4a01746ad4b54eb117d909c07857a52549a3d8bd8f9898648611fb809560e656dfa360b8
7
- data.tar.gz: a2c2042c39354842a10b72d5616dc725ba538b6f7e0ccd01ebd88f98fd84f74635949158aa4e30928c2d4738bc9b02b8faf0a6976563231fce48ce409296ca9b
6
+ metadata.gz: 34a799c1d347f3dadc3030e526b14a964753810d663b76107383145891943592254e886fbe5a53b527dbec6cd08676e572513c0d8fa9e9f76818e7d2d52608a5
7
+ data.tar.gz: cfda628b0bcfa7fffb1bed93cf987241bfebddff79f2c9ddc6d37fa494f877a334ddfb276e6a7e36f922a187ef110c168c564c5f585151b2391536832447cf42
data/README.md CHANGED
@@ -1,33 +1,32 @@
1
- # Conf
1
+ # Confg
2
2
 
3
- This allows the Conf namespace to provide configuration information
3
+ Provides a utility for loading and managing configurations for your ruby project.
4
4
 
5
5
  ## Usage
6
6
 
7
- Conf.configure do |c|
8
- c.app_key = 'core'
9
- c.app_name = 'core'
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
- Feel free to nest as well
14
+ Supports nesting:
13
15
 
14
- Conf.configure do |c|
16
+ Confg.configure do |c|
15
17
  c.api_keys do |a|
16
- a.google_places = 'xyz'
18
+ a.google = 'xyz'
17
19
  a.mixpanel = 'abc'
18
20
  end
19
21
  end
20
22
 
21
- Wanna use yaml files? Cool:
23
+ Load a yaml file:
22
24
 
23
- Conf.configure do |c|
24
- c.load_yaml 'file.yml'
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
- file.yml and core.yml above will be looked for in the Conf.config_dir (which can also be set but defualts to root/config)
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
- Ok, using the values:
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.app_key
41
- # => 'core'
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
@@ -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
- __getobj__[key.to_s]
43
+ fetch(key) { nil }
40
44
  end
41
45
  alias [] get
42
46
 
43
- def get!(key)
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
- set_block(key) do |child|
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
- set_block(key, &block)
106
+ open_block(key, &block)
103
107
  else
104
- get!(key)
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 set_block(key)
118
+ def open_block(key)
115
119
  inner = get(key) || spawn_child
116
120
  yield(inner)
117
121
  set(key, inner)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Confg
4
4
 
5
- VERSION = "2.0.0.rc1"
5
+ VERSION = "2.0.0"
6
6
 
7
7
  end
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.rc1
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-01 00:00:00.000000000 Z
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: 1.3.1
104
+ version: '0'
105
105
  requirements: []
106
106
  rubygems_version: 3.0.3
107
107
  signing_key: