figgy 0.9.0 → 0.9.1
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.
- data/.rvmrc +1 -1
- data/README.md +13 -0
- data/lib/figgy/configuration.rb +12 -6
- data/lib/figgy/hash.rb +5 -1
- data/lib/figgy/version.rb +1 -1
- data/spec/figgy_spec.rb +56 -0
- metadata +14 -15
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use ruby-1.9.3-
|
1
|
+
rvm use ruby-1.9.3-p0@figgy --create
|
data/README.md
CHANGED
@@ -41,6 +41,19 @@ Access it as a dottable, indifferent-access hash:
|
|
41
41
|
AppConfig["foo"]["some_key"]
|
42
42
|
AppConfig[:foo].some_key
|
43
43
|
|
44
|
+
Multiple root directories may be specified, so that configuration files live in
|
45
|
+
more than one place (say, in gems):
|
46
|
+
|
47
|
+
AppConfig = Figgy.build do |config|
|
48
|
+
config.root = Rails.root.join('etc')
|
49
|
+
config.add_root Rails.root.join('vendor/etc')
|
50
|
+
end
|
51
|
+
|
52
|
+
Precedence of root directories is in reverse order of definition, such that the
|
53
|
+
root directory added first (typically the one immediately within the application)
|
54
|
+
has highest precedence. In this way, defaults can be inherited from libraries,
|
55
|
+
but then overridden when necessary within the application.
|
56
|
+
|
44
57
|
## Thanks
|
45
58
|
|
46
59
|
This was written on [Enova Financial's](http://www.enovafinancial.com) dime/time.
|
data/lib/figgy/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Figgy
|
2
2
|
class Configuration
|
3
|
-
# The
|
4
|
-
attr_reader :
|
3
|
+
# The directories in which to search for configuration files
|
4
|
+
attr_reader :roots
|
5
5
|
|
6
6
|
# The list of defined overlays
|
7
7
|
attr_reader :overlays
|
@@ -21,7 +21,7 @@ class Figgy
|
|
21
21
|
# By default, uses a +root+ of the current directory, and defines handlers
|
22
22
|
# for +.yml+, +.yaml+, +.yml.erb+, +.yaml.erb+, and +.json+.
|
23
23
|
def initialize
|
24
|
-
|
24
|
+
@roots = [Dir.pwd]
|
25
25
|
@handlers = []
|
26
26
|
@overlays = []
|
27
27
|
@always_reload = false
|
@@ -43,7 +43,11 @@ class Figgy
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def root=(path)
|
46
|
-
@
|
46
|
+
@roots = [File.expand_path(path)]
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_root(path)
|
50
|
+
@roots.unshift File.expand_path(path)
|
47
51
|
end
|
48
52
|
|
49
53
|
# @see #always_reload=
|
@@ -88,8 +92,10 @@ class Figgy
|
|
88
92
|
|
89
93
|
# @return [Array<String>] the list of directories to search for config files
|
90
94
|
def overlay_dirs
|
91
|
-
return
|
92
|
-
overlay_values.map { |
|
95
|
+
return @roots if @overlays.empty?
|
96
|
+
overlay_values.map { |overlay|
|
97
|
+
@roots.map { |root| overlay ? File.join(root, overlay) : root }
|
98
|
+
}.flatten.uniq
|
93
99
|
end
|
94
100
|
|
95
101
|
# Adds a new handler for files with any extension in +extensions+.
|
data/lib/figgy/hash.rb
CHANGED
data/lib/figgy/version.rb
CHANGED
data/spec/figgy_spec.rb
CHANGED
@@ -101,6 +101,62 @@ describe Figgy do
|
|
101
101
|
second[:still].should == "a dottable hash"
|
102
102
|
second["still"].should == "a dottable hash"
|
103
103
|
end
|
104
|
+
|
105
|
+
it "supports dottable and indifferent setting" do
|
106
|
+
write_config 'values', "number: 1"
|
107
|
+
config = test_config
|
108
|
+
config.values["number"] = 2
|
109
|
+
config.values.number.should == 2
|
110
|
+
config.values[:number] = 3
|
111
|
+
config.values.number.should == 3
|
112
|
+
config.values.number = 4
|
113
|
+
config.values.number.should == 4
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "multiple roots" do
|
118
|
+
it "can be told to read from multiple directories" do
|
119
|
+
write_config 'root1/values', 'foo: 1'
|
120
|
+
write_config 'root2/values', 'bar: 2'
|
121
|
+
|
122
|
+
config = test_config do |config|
|
123
|
+
config.root = File.join(current_dir, 'root1')
|
124
|
+
config.add_root File.join(current_dir, 'root2')
|
125
|
+
end
|
126
|
+
|
127
|
+
config.values.foo.should == 1
|
128
|
+
config.values.bar.should == 2
|
129
|
+
end
|
130
|
+
|
131
|
+
it "supports overlays in each root" do
|
132
|
+
write_config 'root1/values', 'foo: 1'
|
133
|
+
write_config 'root1/prod/values', 'foo: 2'
|
134
|
+
write_config 'root2/values', 'bar: 1'
|
135
|
+
write_config 'root2/prod/values', 'bar: 2'
|
136
|
+
|
137
|
+
config = test_config do |config|
|
138
|
+
config.root = File.join(current_dir, 'root1')
|
139
|
+
config.add_root File.join(current_dir, 'root2')
|
140
|
+
config.define_overlay :environment, 'prod'
|
141
|
+
end
|
142
|
+
|
143
|
+
config.values.foo.should == 2
|
144
|
+
config.values.bar.should == 2
|
145
|
+
end
|
146
|
+
|
147
|
+
it "reads from roots in *reverse* order of definition" do
|
148
|
+
write_config 'root1/values', 'foo: 1'
|
149
|
+
write_config 'root1/prod/values', 'foo: 2'
|
150
|
+
write_config 'root2/prod/values', 'foo: 3'
|
151
|
+
|
152
|
+
config = test_config do |config|
|
153
|
+
config.root = File.join(current_dir, 'root1')
|
154
|
+
config.add_root File.join(current_dir, 'root2')
|
155
|
+
config.define_overlay :environment, 'prod'
|
156
|
+
end
|
157
|
+
|
158
|
+
config.values.foo.should == 2
|
159
|
+
end
|
104
160
|
end
|
105
161
|
|
106
162
|
context "overlays" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: figgy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70290730298440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70290730298440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70290730294020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70290730294020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70290726201420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70290726201420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: simplecov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70290726201000 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70290726201000
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: aruba
|
60
|
-
requirement: &
|
60
|
+
requirement: &70290726200580 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70290726200580
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: heredoc_unindent
|
71
|
-
requirement: &
|
71
|
+
requirement: &70290726200160 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70290726200160
|
80
80
|
description: Access YAML, JSON (and ...) configuration files with ease
|
81
81
|
email:
|
82
82
|
- pd@krh.me
|
@@ -126,4 +126,3 @@ summary: Configuration file reading
|
|
126
126
|
test_files:
|
127
127
|
- spec/figgy_spec.rb
|
128
128
|
- spec/spec_helper.rb
|
129
|
-
has_rdoc:
|