recursive-open-struct 0.6.1 → 0.6.2

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
  SHA1:
3
- metadata.gz: ad6b86b4a8ed2c69543135a33097d06f13e92671
4
- data.tar.gz: bb738b78cb40ff95bb7d257cda73a68b5dec6f7b
3
+ metadata.gz: 765e14c47a76030b5a36300eea04264d3a9daf19
4
+ data.tar.gz: 8370dfc8bde5246291aec3594f3d27ea0162194c
5
5
  SHA512:
6
- metadata.gz: fd1efd0c19bc1e6418592d071b32fcf5df03a341b852f6e1c4a5a75f7cf120494135a518011348848718c960e96414e1db033a985e388dca1060790fd7f9e922
7
- data.tar.gz: 8a2e0a8592dac362652a0e8adb369b4b611df7cdbab37c55dd8cae75bad1ca6cc1976f11fedfa4d751fa0ae099e0a44551368ae838e76cedb3591ab06585aae1
6
+ metadata.gz: 05fea524625e1b5cef5cae0ca8e6aa46e459802cc93be57984e8cc7586c797221fa65d57e02c95f1cf0e73f2745110ddfb2478b3153431f51b9113c62987fd7f
7
+ data.tar.gz: a2459d5a3655c0aa1508a7e3d52f6ff45a9ccbac695b404acb6f902e3fc343a8a85237ae897d8f9af4fea93b218d1f39aab98e55a7bc0ef0d434a50c319a7ce8
@@ -1,3 +1,11 @@
1
+ 0.6.2 / 2015-04-07
2
+ ==================
3
+
4
+ * FIX: fervic: Address a bug in the Ruby 1.9's version of OpenStruct's `dup`
5
+ * FIX: Victor Guzman: Reset memoized values on assignment in order to force the
6
+ implementation to re-memoize them.
7
+ * MAINT: fervic: Simplified `initialize`
8
+
1
9
  0.6.1 / 2015-03-28
2
10
  ==================
3
11
 
data/Gemfile CHANGED
@@ -1,12 +1,2 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
-
4
- gem 'pry'
5
-
6
- group :development do
7
- if RUBY_VERSION =~ /^1\.8/
8
- gem 'rcov'
9
- else
10
- gem 'simplecov'
11
- end
12
- end
@@ -7,35 +7,31 @@ require 'recursive_open_struct/deep_dup'
7
7
  class RecursiveOpenStruct < OpenStruct
8
8
  include DebugInspect
9
9
 
10
- def initialize(hash=nil, args={})
10
+ def initialize(hash={}, args={})
11
11
  @recurse_over_arrays = args.fetch(:recurse_over_arrays, false)
12
- mutate_input_hash = args.fetch(:mutate_input_hash, false)
12
+ @deep_dup = DeepDup.new(recurse_over_arrays: @recurse_over_arrays)
13
13
 
14
- unless mutate_input_hash
15
- hash = DeepDup.new(recurse_over_arrays: @recurse_over_arrays).call(hash)
16
- end
17
-
18
- super(hash)
19
-
20
- if mutate_input_hash && hash
21
- hash.clear
22
- @table.each { |k,v| hash[k] = v }
23
- @table = hash
24
- end
14
+ @table = args.fetch(:mutate_input_hash, false) ? hash : @deep_dup.call(hash)
15
+ @table && @table.each_key { |k| new_ostruct_member(k.to_sym) }
25
16
 
26
17
  @sub_elements = {}
27
18
  end
28
19
 
29
20
  def initialize_copy(orig)
30
21
  super
22
+
23
+ # Apply fix if necessary:
24
+ # https://github.com/ruby/ruby/commit/2d952c6d16ffe06a28bb1007e2cd1410c3db2d58
25
+ @table.each_key{|key| new_ostruct_member(key)} if RUBY_VERSION =~ /^1.9/
26
+
31
27
  # deep copy the table to separate the two objects
32
- @table = DeepDup.new(recurse_over_arrays: @recurse_over_arrays).call(orig.instance_variable_get(:@table))
28
+ @table = @deep_dup.call(orig.instance_variable_get(:@table))
33
29
  # Forget any memoized sub-elements
34
30
  @sub_elements = {}
35
31
  end
36
32
 
37
33
  def to_h
38
- DeepDup.new(recurse_over_arrays: @recurse_over_arrays).call(@table)
34
+ @deep_dup.call(@table)
39
35
  end
40
36
 
41
37
  alias_method :to_hash, :to_h
@@ -60,7 +56,10 @@ class RecursiveOpenStruct < OpenStruct
60
56
  v
61
57
  end
62
58
  end
63
- define_method("#{name}=") { |x| modifiable[name] = x }
59
+ define_method("#{name}=") do |x|
60
+ @sub_elements.delete(name)
61
+ modifiable[name] = x
62
+ end
64
63
  define_method("#{name}_as_a_hash") { @table[name] }
65
64
  end
66
65
  end
@@ -3,5 +3,5 @@
3
3
  require 'ostruct'
4
4
 
5
5
  class RecursiveOpenStruct < OpenStruct
6
- VERSION = "0.6.1"
6
+ VERSION = "0.6.2"
7
7
  end
@@ -34,9 +34,11 @@ Gem::Specification.new do |s|
34
34
  "README.md"
35
35
  ]
36
36
 
37
+ s.add_development_dependency('bundler', [">= 0"])
38
+ s.add_development_dependency('pry', [">= 0"])
39
+ s.add_development_dependency('rake', [">= 0"])
40
+ s.add_development_dependency('rdoc', [">= 0"])
37
41
  s.add_development_dependency('rspec', "~> 3.2")
38
- s.add_development_dependency(%q<bundler>, [">= 0"])
39
- s.add_development_dependency(%q<rdoc>, [">= 0"])
40
- s.add_development_dependency(%q<rake>, [">= 0"])
42
+ s.add_development_dependency('simplecov', [">= 0"])
41
43
  end
42
44
 
@@ -149,6 +149,40 @@ describe RecursiveOpenStruct do
149
149
  end
150
150
  end
151
151
 
152
+ context "when memoizing and then modifying entire recursive structures" do
153
+ subject do
154
+ RecursiveOpenStruct.new(
155
+ { :blah => original_blah }, :recurse_over_arrays => true)
156
+ end
157
+
158
+ before(:each) { subject.blah } # enforce memoization
159
+
160
+ context "when modifying an entire Hash" do
161
+ let(:original_blah) { { :a => 'A', :b => 'B' } }
162
+ let(:new_blah) { { :something_new => "C" } }
163
+
164
+ before(:each) { subject.blah = new_blah }
165
+
166
+ it "returns the modified value instead of the memoized one" do
167
+ subject.blah.something_new.should == "C"
168
+ end
169
+
170
+ specify "the old value no longer exists" do
171
+ subject.blah.a.should be_nil
172
+ end
173
+ end
174
+
175
+ context "when modifying an entire Array" do
176
+ let(:original_blah) { [1, 2, 3] }
177
+
178
+ it "returns the modified value instead of the memoized one" do
179
+ new_blah = [4, 5, 6]
180
+ subject.blah = new_blah
181
+ subject.blah.should == new_blah
182
+ end
183
+ end
184
+ end
185
+
152
186
  describe 'recursing over arrays' do
153
187
  let(:blah_list) { [ { :foo => '1' }, { :foo => '2' }, 'baz' ] }
154
188
  let(:h) { { :blah => blah_list } }
metadata CHANGED
@@ -1,31 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recursive-open-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William (B.J.) Snow Orvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-28 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - '>='
@@ -53,7 +67,21 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rake
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - '>='