nested_config 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3e61291df4a84b9d787f55e4e25950916b47491
4
+ data.tar.gz: 753fdf2d4c08633e1db24ba88c6a5e275e0c0372
5
+ SHA512:
6
+ metadata.gz: 9c4b5c1204481ed4d1971c17a5141bf2a1b0caffea9194aa48794bbc41fd1cea5ef6b3c9104cf13c9e49cd2fb2692a0e3f898175158ba4c47bc3a0521080db8b
7
+ data.tar.gz: 0d72f78de137a1775d6fe5ea786225ce71fd22c52e44771ca3f4bee16d40f68f8a0f9fe44cc333f17033ea9f4dd90deafe9e3b3fbcc154e0eff513b93cc566df
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1
data/.travis.yml CHANGED
@@ -1,8 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - ree
3
+ - 2.1
4
+ - 2.0
4
5
  - 1.9.3
5
- - jruby-18mode
6
6
  - jruby-19mode
7
- - rbx-18mode
8
7
  - rbx-19mode
data/Gemfile CHANGED
@@ -2,7 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- group :test do
6
- gem 'simplecov', :require => false
7
- gem 'simplecov-rcov', :require => false
5
+ if ENV['COVERAGE']
6
+ group :test do
7
+ gem 'simplecov', :require => false
8
+ gem 'simplecov-rcov', :require => false
9
+ end
8
10
  end
data/README.rdoc CHANGED
@@ -1,10 +1,12 @@
1
- = nested_config {<img src="https://secure.travis-ci.org/neopoly/nested_config.png?branch=master" alt="Build Status" />}[http://travis-ci.org/neopoly/nested_config]
1
+ = nested_config
2
+
3
+ {<img src="http://img.shields.io/travis/neopoly/nested_config.svg" alt="Build Status" />}[http://travis-ci.org/neopoly/nested_config] {<img src="http://img.shields.io/gem/v/nested_config.svg" alt="Gem Version" />}[http://rubygems.org/gems/nested_config] {<img src="http://img.shields.io/codeclimate/github/neopoly/nested_config.svg" />}[https://codeclimate.com/github/neopoly/nested_config] {<img src="http://inch-ci.org/github/neopoly/nested_config.svg?branch=master" alt="Inline docs" />}[http://inch-ci.org/github/neopoly/nested_config]
2
4
 
3
5
  Simple, static, nested application configuration
4
6
 
5
7
  Gem[https://rubygems.org/gems/nested_config] |
6
8
  Source[https://github.com/neopoly/nested_config] |
7
- RDoc[http://rubydoc.info/github/neopoly/nested_config/master/file/README.rdoc]
9
+ Documentation[http://rubydoc.info/github/neopoly/nested_config/master/file/README.rdoc]
8
10
 
9
11
  == Usage
10
12
 
@@ -117,7 +119,11 @@ This can be used in tests modifying a global application config inside a block:
117
119
  == Test
118
120
 
119
121
  rake test
120
- COVERAGE=1 rake test
122
+ COVERAGE=1 bundle exec rake test
123
+
124
+ == TODO
125
+
126
+ * Make NestedConfig a blank slate
121
127
 
122
128
  == Release
123
129
 
data/lib/nested_config.rb CHANGED
@@ -23,7 +23,7 @@ class NestedConfig
23
23
  backup = Marshal.load(Marshal.dump(@hash))
24
24
  yield(self)
25
25
  ensure
26
- @hash = backup
26
+ @hash = backup if backup
27
27
  end
28
28
 
29
29
  def inspect
@@ -1,3 +1,3 @@
1
1
  class NestedConfig
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -42,17 +42,24 @@ class NestedConfig
42
42
  # end
43
43
  module WithConfig
44
44
  def with_config(config, *keys, &block)
45
- current = config
46
- while key = keys.shift
47
- current = current[key]
48
- unless current
49
- raise ArgumentError, "nested key #{key.inspect} not found"
50
- end
51
- end
52
- unless current.respond_to?(:__with_cloned__)
53
- raise ArgumentError, "config #{current.inspect} can't be cloned"
45
+ current = keys.inject(config) do |config, key|
46
+ config[key] or raise KeyNotFound.new(key, keys)
54
47
  end
48
+ current.respond_to?(:__with_cloned__) or raise ValueNotCloneable.new(current)
49
+
55
50
  current.__with_cloned__(&block)
56
51
  end
52
+
53
+ class KeyNotFound < ArgumentError
54
+ def initialize(key, keys)
55
+ super(%{config key "#{key}" in config.#{keys.map(&:to_s).join(".")} not found})
56
+ end
57
+ end
58
+
59
+ class ValueNotCloneable < ArgumentError
60
+ def initialize(value)
61
+ super(%{config value #{value.inspect} can't be cloned})
62
+ end
63
+ end
57
64
  end
58
65
  end
data/test/helper.rb CHANGED
@@ -1,7 +1,8 @@
1
- # simplecov
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
2
4
  require 'simplecov' if ENV['COVERAGE']
3
5
 
4
- require 'rubygems'
5
6
  require 'minitest/spec'
6
7
  require 'minitest/autorun'
7
8
 
@@ -57,17 +57,17 @@ class NestedConfigWithConfigTest < NestedConfigSpec
57
57
  end
58
58
 
59
59
  test "key not found raises ArgumentError" do
60
- error = assert_raises ArgumentError do
60
+ error = assert_raises NestedConfig::WithConfig::KeyNotFound do
61
61
  with_config(config, :some_key, :not_found) {}
62
62
  end
63
- assert_match %r{not found}, error.message
63
+ assert_equal %{config key "some_key" in config.some_key.not_found not found}, error.message
64
64
  end
65
65
 
66
66
  test "can't change basic value" do
67
- error = assert_raises ArgumentError do
67
+ error = assert_raises NestedConfig::WithConfig::ValueNotCloneable do
68
68
  with_config(config, :basic) {}
69
69
  end
70
- assert_match %r{can't be cloned}, error.message
70
+ assert_equal %{config value 23 can't be cloned}, error.message
71
71
  end
72
72
  end
73
73
  end
@@ -153,6 +153,16 @@ class NestedConfigTest < NestedConfigSpec
153
153
  end
154
154
  assert_equal 2, config.nest.deep.level
155
155
  end
156
+
157
+ test "still usable if it's undumpable" do
158
+ config.undumpable = proc {}
159
+
160
+ assert_raises TypeError do
161
+ config.__with_cloned__ {}
162
+ end
163
+
164
+ assert_equal 1, config.top_level
165
+ end
156
166
  end
157
167
  end
158
168
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.4.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Suschlik
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-16 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rdoc
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: ''
@@ -66,10 +59,10 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .gitignore
70
- - .rvmrc
71
- - .simplecov
72
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".ruby-version"
64
+ - ".simplecov"
65
+ - ".travis.yml"
73
66
  - Gemfile
74
67
  - README.rdoc
75
68
  - Rakefile
@@ -84,26 +77,25 @@ files:
84
77
  - test/nested_config_test.rb
85
78
  homepage: https://rubygems.org/gems/nested_config
86
79
  licenses: []
80
+ metadata: {}
87
81
  post_install_message:
88
82
  rdoc_options: []
89
83
  require_paths:
90
84
  - lib
91
85
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
86
  requirements:
94
- - - ! '>='
87
+ - - ">="
95
88
  - !ruby/object:Gem::Version
96
89
  version: '0'
97
90
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
91
  requirements:
100
- - - ! '>='
92
+ - - ">="
101
93
  - !ruby/object:Gem::Version
102
94
  version: '0'
103
95
  requirements: []
104
96
  rubyforge_project:
105
- rubygems_version: 1.8.24
97
+ rubygems_version: 2.2.2
106
98
  signing_key:
107
- specification_version: 3
99
+ specification_version: 4
108
100
  summary: Simple, static, nested config
109
101
  test_files: []
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm 1.9.3@nested_config --create