figgy 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzlmMTc5ZjUyYzI2MTc5YjJiNDFhZTRkMDljYjc0MzhmNTc5MGNmZA==
5
+ data.tar.gz: !binary |-
6
+ ODJmMGFhZjNhNjA3NmU5YmY5ZWZlMjZjZTdhMjMyOTdmMDFlM2E4Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YWVlNDkwNDdlMTJjNTMyZmJiOTZmNmRlN2Q0Y2E3NzM4NTg1NGUwYmExMjk1
10
+ MmU1NTg3ODYxNWExOTJmMmY1MjJlODZjOWJiYTMwMzI2N2YwYzRlN2IxMDNj
11
+ Y2Y4Yjg4MGFlM2Y4NmQ5NDk2MGFiODY3MDcyYzJmZmI3Njk0YTQ=
12
+ data.tar.gz: !binary |-
13
+ ZmJiYjZlYmUzYTkzYzM1ODUxZWFmMGU0YjY4YjlkMmJhNDJiZTFmNmVlOGQx
14
+ ZTIwYThlNTE4ZWE1NGI0YjBjYWU3MmQwNGExYWY2YjNiZTc3MzI0M2I3Y2Nl
15
+ NWI5NDQwZWRiYzA4ZGRjYzFmNzgxZmQ3MTU1MmZmNTlhZDEwYjc=
data/.travis.yml CHANGED
@@ -2,3 +2,5 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kyle Hargraves
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -14,46 +14,67 @@ any other arbitrary thing you happen to come up with.
14
14
 
15
15
  Just like everything else these days. In your Gemfile:
16
16
 
17
- gem 'figgy'
17
+ ~~~ruby
18
+ gem 'figgy'
19
+ ~~~
18
20
 
19
21
  ## Overview
20
22
 
21
23
  Set it up (say, in a Rails initializer):
22
24
 
23
- AppConfig = Figgy.build do |config|
24
- config.root = Rails.root.join('etc')
25
+ ~~~ruby
26
+ AppConfig = Figgy.build do |config|
27
+ config.root = Rails.root.join('etc')
25
28
 
26
- # config.foo is read from etc/foo.yml
27
- config.define_overlay :default, nil
29
+ # config.foo is read from etc/foo.yml
30
+ config.define_overlay :default, nil
28
31
 
29
- # config.foo is then updated with values from etc/production/foo.yml
30
- config.define_overlay(:environment) { Rails.env }
32
+ # config.foo is then updated with values from etc/production/foo.yml
33
+ config.define_overlay(:environment) { Rails.env }
31
34
 
32
- # Maybe you need to load XML files?
33
- config.define_handler 'xml' do |contents|
34
- Hash.from_xml(contents)
35
- end
36
- end
35
+ # Maybe you need to load XML files?
36
+ config.define_handler 'xml' do |contents|
37
+ Hash.from_xml(contents)
38
+ end
39
+ end
40
+ ~~~
37
41
 
38
42
  Access it as a dottable, indifferent-access hash:
39
43
 
40
- AppConfig.foo.some_key
41
- AppConfig["foo"]["some_key"]
42
- AppConfig[:foo].some_key
44
+ ~~~ruby
45
+ AppConfig.foo.some_key
46
+ AppConfig["foo"]["some_key"]
47
+ AppConfig[:foo].some_key
48
+ ~~~
43
49
 
44
50
  Multiple root directories may be specified, so that configuration files live in
45
51
  more than one place (say, in gems):
46
52
 
47
- AppConfig = Figgy.build do |config|
48
- config.root = Rails.root.join('etc')
49
- config.add_root Rails.root.join('vendor/etc')
50
- end
53
+ ~~~ruby
54
+ AppConfig = Figgy.build do |config|
55
+ config.root = Rails.root.join('etc')
56
+ config.add_root Rails.root.join('vendor/etc')
57
+ end
58
+ ~~~
51
59
 
52
60
  Precedence of root directories is in reverse order of definition, such that the
53
61
  root directory added first (typically the one immediately within the application)
54
62
  has highest precedence. In this way, defaults can be inherited from libraries,
55
63
  but then overridden when necessary within the application.
56
64
 
65
+ ## Caveats
66
+
67
+ Because the objects exposed by figgy are often hashes, all of the instance methods
68
+ of Hash (and, of course, Enumerable) are available along the chain. But note that
69
+ this means you can not use key names such as `size` or `each` with the dottable
70
+ access style:
71
+
72
+ ~~~ruby
73
+ AppConfig.price.bulk #=> 100.00
74
+ AppConfig.price.each #=> attempts to invoke Hash#each
75
+ AppConfig.price[:each] #=> 50.00
76
+ ~~~
77
+
57
78
  ## Thanks
58
79
 
59
- This was written on [Enova Financial's](http://www.enovafinancial.com) dime/time.
80
+ This was written on [Enova's](http://www.enova.com) dime/time.
data/figgy.gemspec CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "http://github.com/pd/figgy"
11
11
  s.summary = %q{Configuration file reading}
12
12
  s.description = %q{Access YAML, JSON (and ...) configuration files with ease}
13
+ s.license = 'MIT'
13
14
 
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -18,7 +19,7 @@ Gem::Specification.new do |s|
18
19
 
19
20
  s.add_dependency "json"
20
21
  s.add_development_dependency "rake"
21
- s.add_development_dependency "rspec"
22
+ s.add_development_dependency "rspec", '~> 2.14.0'
22
23
  s.add_development_dependency "simplecov"
23
24
  s.add_development_dependency "aruba"
24
25
  s.add_development_dependency "heredoc_unindent"
data/lib/figgy/finder.rb CHANGED
@@ -17,7 +17,12 @@ class Figgy
17
17
  # @return Whatever was in the config file loaded
18
18
  # @raise [Figgy::FileNotFound] if no config file could be found for +name+
19
19
  def load(name)
20
- result = files_for(name).reduce(nil) do |result, file|
20
+ files = files_for(name)
21
+ if files.empty?
22
+ raise(Figgy::FileNotFound, "Can't find config files for key: #{name.inspect}")
23
+ end
24
+
25
+ result = files.reduce(nil) do |result, file|
21
26
  object = @config.handler_for(file).call(File.read(file))
22
27
  if result && result.respond_to?(:merge)
23
28
  deep_merge(result, object)
@@ -26,7 +31,6 @@ class Figgy
26
31
  end
27
32
  end
28
33
 
29
- raise(Figgy::FileNotFound, "Can't find config files for key: #{name.inspect}") unless result
30
34
  deep_freeze(to_figgy_hash(result))
31
35
  end
32
36
 
data/lib/figgy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Figgy
2
- VERSION = "0.9.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/figgy.rb CHANGED
@@ -42,6 +42,10 @@ class Figgy
42
42
  end
43
43
  end
44
44
 
45
+ def [](key)
46
+ @store.get(key)
47
+ end
48
+
45
49
  def method_missing(m, *args, &block)
46
50
  @store.get(m)
47
51
  end
data/spec/figgy_spec.rb CHANGED
@@ -112,6 +112,62 @@ describe Figgy do
112
112
  config.values.number = 4
113
113
  config.values.number.should == 4
114
114
  end
115
+
116
+ it "supports indifferent hash notation on the top-level config object" do
117
+ write_config 'values', "number: 1"
118
+ config = test_config
119
+ config['values'].should == config.values
120
+ config[:values].should == config.values
121
+ end
122
+
123
+ context "performing basic hash operations" do
124
+ let(:config) do
125
+ write_config 'values', <<-YML
126
+ with:
127
+ one: 1
128
+ two: 2
129
+ without:
130
+ two: 2
131
+ another:
132
+ three: 3
133
+ altogether:
134
+ one: 1
135
+ two: 2
136
+ three: 3
137
+ YML
138
+ test_config
139
+ end
140
+
141
+ it "can delete a key" do
142
+ config.values.with.delete(:one).should == 1
143
+ config.values.with.should == config.values.without
144
+ end
145
+
146
+ it "can look up values for a list of keys" do
147
+ config.values.with.values_at(:one,:two).should == [1,2]
148
+ end
149
+
150
+ it "can merge with another hash" do
151
+ config.values.with.merge(config.values.another).should == config.values.altogether
152
+ end
153
+ end
154
+ end
155
+
156
+ context 'oddities' do
157
+ it "returns false for empty files (cf. YAML.load(''))" do
158
+ write_config 'empty', ''
159
+ test_config.empty.should == false
160
+ end
161
+
162
+ it "returns false for files containing a literal false" do
163
+ write_config 'maybe', 'false'
164
+ test_config.maybe.should == false
165
+ end
166
+
167
+ it "returns nil when explicitly set to that value in the YAML file" do
168
+ write_config 'reason_to_do_this', nil.to_yaml
169
+ test_config.reason_to_do_this.should == nil
170
+ end
115
171
  end
116
172
 
117
173
  context "multiple roots" do
@@ -343,12 +399,12 @@ describe Figgy do
343
399
 
344
400
  context "freezing" do
345
401
  it "leaves results unfrozen by default" do
346
- write_config 'values', 'foo: 1'
402
+ write_config 'values', "foo: '1'"
347
403
  test_config.values.foo.should_not be_frozen
348
404
  end
349
405
 
350
406
  it "freezes the results when config.freeze = true" do
351
- write_config 'values', 'foo: 1'
407
+ write_config 'values', "foo: '1'"
352
408
  config = test_config do |config|
353
409
  config.freeze = true
354
410
  end
@@ -382,11 +438,3 @@ describe Figgy do
382
438
  end
383
439
  end
384
440
  end
385
-
386
- describe Figgy do
387
- describe 'CnuConfig drop-in compatibility' do
388
- it "should maybe support path_formatter = some_proc.call(config_name, overlays)"
389
- it "should support preload's all_key_names when using path_formatter"
390
- it "should support preload's all_key_names when using path_formatter"
391
- end
392
- end
metadata CHANGED
@@ -1,82 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figgy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kyle Hargraves
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000 Z
11
+ date: 2014-06-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
- requirement: &70290730298440 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70290730298440
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rake
27
- requirement: &70290730294020 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ! '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70290730294020
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &70290726201420 !ruby/object:Gem::Requirement
39
- none: false
36
+ version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - ! '>='
42
39
  - !ruby/object:Gem::Version
43
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.0
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70290726201420
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.0
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: simplecov
49
- requirement: &70290726201000 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70290726201000
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: aruba
60
- requirement: &70290726200580 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
73
  - - ! '>='
64
74
  - !ruby/object:Gem::Version
65
75
  version: '0'
66
76
  type: :development
67
77
  prerelease: false
68
- version_requirements: *70290726200580
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: heredoc_unindent
71
- requirement: &70290726200160 !ruby/object:Gem::Requirement
72
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
73
86
  requirements:
74
87
  - - ! '>='
75
88
  - !ruby/object:Gem::Version
76
89
  version: '0'
77
90
  type: :development
78
91
  prerelease: false
79
- version_requirements: *70290726200160
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
80
97
  description: Access YAML, JSON (and ...) configuration files with ease
81
98
  email:
82
99
  - pd@krh.me
@@ -85,9 +102,9 @@ extensions: []
85
102
  extra_rdoc_files: []
86
103
  files:
87
104
  - .gitignore
88
- - .rvmrc
89
105
  - .travis.yml
90
106
  - Gemfile
107
+ - LICENSE.txt
91
108
  - README.md
92
109
  - Rakefile
93
110
  - figgy.gemspec
@@ -100,29 +117,30 @@ files:
100
117
  - spec/figgy_spec.rb
101
118
  - spec/spec_helper.rb
102
119
  homepage: http://github.com/pd/figgy
103
- licenses: []
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
104
123
  post_install_message:
105
124
  rdoc_options: []
106
125
  require_paths:
107
126
  - lib
108
127
  required_ruby_version: !ruby/object:Gem::Requirement
109
- none: false
110
128
  requirements:
111
129
  - - ! '>='
112
130
  - !ruby/object:Gem::Version
113
131
  version: '0'
114
132
  required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
133
  requirements:
117
134
  - - ! '>='
118
135
  - !ruby/object:Gem::Version
119
136
  version: '0'
120
137
  requirements: []
121
138
  rubyforge_project:
122
- rubygems_version: 1.8.10
139
+ rubygems_version: 2.2.2
123
140
  signing_key:
124
- specification_version: 3
141
+ specification_version: 4
125
142
  summary: Configuration file reading
126
143
  test_files:
127
144
  - spec/figgy_spec.rb
128
145
  - spec/spec_helper.rb
146
+ has_rdoc:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3-p0@figgy --create