configatron 4.2.0 → 4.2.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/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 4.2.1
2
+
3
+ * Fix a bug with deep cloning which caused temping to break for nested settings
4
+
1
5
  === 4.2.0
2
6
 
3
7
  * [backwards-incompatible] Make to_h/to_hash recursively hashify Configatron::Stores, and resolve Configatron::Procs.
@@ -37,8 +37,16 @@ module Configatron::DeepClone
37
37
  def self.deep_clone( obj=self, cloned={} )
38
38
  if Configatron::RootStore === obj
39
39
  # We never actually want to have multiple copies of our
40
- # Configatron::RootStore (and every Store has a reference).
40
+ # Configatron::RootStore -- when making a temp, we just stick
41
+ # the state-to-revert-to into an ivar.
41
42
  return obj
43
+ elsif Configatron::Store === obj
44
+ # Need to special-case this since it's a BasicObject, meaning it
45
+ # doesn't respond to all the usual ivar magic methods
46
+ cl = obj.clone(cloned)
47
+ cloned[obj.__id__] = cl
48
+ cloned[cl.__id__] = cl
49
+ return cl
42
50
  elsif cloned.key?( obj.__id__ )
43
51
  return cloned[obj.__id__]
44
52
  else
@@ -52,7 +60,6 @@ module Configatron::DeepClone
52
60
  cloned[obj.__id__] = cl
53
61
  cloned[cl.__id__] = cl
54
62
  case
55
- when Configatron::Store === cl then return cl
56
63
  when Hash === cl
57
64
  cl.clone.each do |k,v|
58
65
  cl[k] = deep_clone( v, cloned )
@@ -88,8 +88,12 @@ class Configatron
88
88
  end
89
89
 
90
90
  # Needed for deep_clone to actually clone this object
91
- def clone
92
- Store.new(@root_store, @name, @attributes.clone)
91
+ def clone(cloned={})
92
+ root_store = DeepClone.deep_clone(@root_store, cloned)
93
+ name = DeepClone.deep_clone(@name, cloned)
94
+ attributes = DeepClone.deep_clone(@attributes, cloned)
95
+
96
+ Store.new(root_store, name, attributes)
93
97
  end
94
98
 
95
99
  def to_h
@@ -1,3 +1,3 @@
1
1
  class Configatron
2
- VERSION = "4.2.0"
2
+ VERSION = "4.2.1"
3
3
  end
@@ -26,6 +26,15 @@ class Critic::Functional::ConfigatronTest < Critic::Functional::Test
26
26
  assert_equal(false, @kernel.key?(:c))
27
27
  end
28
28
 
29
+ it 'nested' do
30
+ @kernel.foo.bar = 'original'
31
+ @kernel.temp do
32
+ @kernel.foo.bar = 'temp'
33
+ assert_equal('temp', @kernel.foo.bar)
34
+ end
35
+ assert_equal('original', @kernel.foo.bar)
36
+ end
37
+
29
38
  describe 'start/end' do
30
39
  it 'allows for temporary setting of values' do
31
40
  assert_equal('A', @kernel.a)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-25 00:00:00.000000000 Z
12
+ date: 2014-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -138,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  segments:
140
140
  - 0
141
- hash: -3864894795624167904
141
+ hash: -3339507519042551569
142
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  none: false
144
144
  requirements:
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  segments:
149
149
  - 0
150
- hash: -3864894795624167904
150
+ hash: -3339507519042551569
151
151
  requirements: []
152
152
  rubyforge_project:
153
153
  rubygems_version: 1.8.25