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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -11
- data/lib/recursive_open_struct.rb +15 -16
- data/lib/recursive_open_struct/version.rb +1 -1
- data/recursive-open-struct.gemspec +5 -3
- data/spec/recursive_open_struct_spec.rb +34 -0
- metadata +37 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765e14c47a76030b5a36300eea04264d3a9daf19
|
4
|
+
data.tar.gz: 8370dfc8bde5246291aec3594f3d27ea0162194c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05fea524625e1b5cef5cae0ca8e6aa46e459802cc93be57984e8cc7586c797221fa65d57e02c95f1cf0e73f2745110ddfb2478b3153431f51b9113c62987fd7f
|
7
|
+
data.tar.gz: a2459d5a3655c0aa1508a7e3d52f6ff45a9ccbac695b404acb6f902e3fc343a8a85237ae897d8f9af4fea93b218d1f39aab98e55a7bc0ef0d434a50c319a7ce8
|
data/CHANGELOG.md
CHANGED
@@ -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
@@ -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=
|
10
|
+
def initialize(hash={}, args={})
|
11
11
|
@recurse_over_arrays = args.fetch(:recurse_over_arrays, false)
|
12
|
-
|
12
|
+
@deep_dup = DeepDup.new(recurse_over_arrays: @recurse_over_arrays)
|
13
13
|
|
14
|
-
|
15
|
-
|
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 =
|
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
|
-
|
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}=")
|
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
|
@@ -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(
|
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.
|
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-
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
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:
|
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
|
- - '>='
|