deep_dive 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/workspace.xml +31 -23
- data/.semver +1 -1
- data/README.rdoc +46 -9
- data/deep_dive.gemspec +1 -1
- data/lib/deep_dive/deep_dive.rb +11 -2
- data/spec/lib/deep_dive/deep_dive_spec.rb +6 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b53f0db147c075992df86e4800da412bc39d2f
|
4
|
+
data.tar.gz: 5df897b75bddf97278a92b7674e6aa5dfc4b0c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80d7ebd8544568fc165ee58cc4290a9198b18184af289ebf6394b4343ec6d68452c56edd091bb2e36622435ea9da2709897c8b6acd5b7e70c3dcca3c66f3cb02
|
7
|
+
data.tar.gz: db46403f21891545c8130a00147923164d160e7854e9c7c62f488da5faa98fc46a8e773b445a54ae9a59ecb114303cbcf7f15e6b7f3e928552e3586a76f80557
|
data/.idea/workspace.xml
CHANGED
@@ -37,7 +37,7 @@
|
|
37
37
|
<file leaf-file-name="deep_dive.rb" pinned="false" current="false" current-in-tab="false">
|
38
38
|
<entry file="file://$PROJECT_DIR$/lib/deep_dive/deep_dive.rb">
|
39
39
|
<provider selected="true" editor-type-id="text-editor">
|
40
|
-
<state line="
|
40
|
+
<state line="54" column="70" selection-start="1678" selection-end="1678" vertical-scroll-proportion="0.0" vertical-offset="632" max-vertical-offset="2100">
|
41
41
|
<folding />
|
42
42
|
</state>
|
43
43
|
</provider>
|
@@ -46,7 +46,7 @@
|
|
46
46
|
<file leaf-file-name="deep_dive.gemspec" pinned="false" current="false" current-in-tab="true">
|
47
47
|
<entry file="file://$PROJECT_DIR$/deep_dive.gemspec">
|
48
48
|
<provider selected="true" editor-type-id="text-editor">
|
49
|
-
<state line="
|
49
|
+
<state line="28" column="26" selection-start="1199" selection-end="1199" vertical-scroll-proportion="0.4259635" vertical-offset="0" max-vertical-offset="1230">
|
50
50
|
<folding />
|
51
51
|
</state>
|
52
52
|
</provider>
|
@@ -56,19 +56,19 @@
|
|
56
56
|
</split-first>
|
57
57
|
<split-second>
|
58
58
|
<leaf>
|
59
|
-
<file leaf-file-name="
|
60
|
-
<entry file="file://$PROJECT_DIR$/
|
59
|
+
<file leaf-file-name="README.rdoc" pinned="false" current="true" current-in-tab="true">
|
60
|
+
<entry file="file://$PROJECT_DIR$/README.rdoc">
|
61
61
|
<provider selected="true" editor-type-id="text-editor">
|
62
|
-
<state line="
|
62
|
+
<state line="56" column="0" selection-start="1693" selection-end="1693" vertical-scroll-proportion="0.851927" vertical-offset="0" max-vertical-offset="1065">
|
63
63
|
<folding />
|
64
64
|
</state>
|
65
65
|
</provider>
|
66
66
|
</entry>
|
67
67
|
</file>
|
68
|
-
<file leaf-file-name="
|
69
|
-
<entry file="file://$PROJECT_DIR$/
|
68
|
+
<file leaf-file-name="deep_dive_spec.rb" pinned="false" current="false" current-in-tab="false">
|
69
|
+
<entry file="file://$PROJECT_DIR$/spec/lib/deep_dive/deep_dive_spec.rb">
|
70
70
|
<provider selected="true" editor-type-id="text-editor">
|
71
|
-
<state line="
|
71
|
+
<state line="34" column="0" selection-start="357" selection-end="770" vertical-scroll-proportion="0.0" vertical-offset="45" max-vertical-offset="1410">
|
72
72
|
<folding />
|
73
73
|
</state>
|
74
74
|
</provider>
|
@@ -87,11 +87,12 @@
|
|
87
87
|
<option name="changedFiles">
|
88
88
|
<list>
|
89
89
|
<option value="$PROJECT_DIR$/Gemfile" />
|
90
|
-
<option value="$PROJECT_DIR$/lib/deep_dive/deep_dive.rb" />
|
91
|
-
<option value="$PROJECT_DIR$/README.rdoc" />
|
92
90
|
<option value="$PROJECT_DIR$/lib/deep_dive/version.rb" />
|
93
|
-
<option value="$PROJECT_DIR$/deep_dive.gemspec" />
|
94
91
|
<option value="$PROJECT_DIR$/Rakefile" />
|
92
|
+
<option value="$PROJECT_DIR$/lib/deep_dive/deep_dive.rb" />
|
93
|
+
<option value="$PROJECT_DIR$/spec/lib/deep_dive/deep_dive_spec.rb" />
|
94
|
+
<option value="$PROJECT_DIR$/deep_dive.gemspec" />
|
95
|
+
<option value="$PROJECT_DIR$/README.rdoc" />
|
95
96
|
</list>
|
96
97
|
</option>
|
97
98
|
</component>
|
@@ -380,8 +381,8 @@
|
|
380
381
|
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3294347" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
381
382
|
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3294347" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
382
383
|
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
383
|
-
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.
|
384
|
-
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.
|
384
|
+
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.19743863" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
385
|
+
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.17982924" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
385
386
|
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
386
387
|
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
|
387
388
|
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
|
@@ -450,44 +451,51 @@
|
|
450
451
|
</state>
|
451
452
|
</provider>
|
452
453
|
</entry>
|
453
|
-
<entry file="file://$PROJECT_DIR
|
454
|
+
<entry file="file://$PROJECT_DIR$/.semver">
|
454
455
|
<provider selected="true" editor-type-id="text-editor">
|
455
|
-
<state line="
|
456
|
+
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="999">
|
456
457
|
<folding />
|
457
458
|
</state>
|
458
459
|
</provider>
|
459
460
|
</entry>
|
460
|
-
<entry file="file://$PROJECT_DIR
|
461
|
+
<entry file="file://$PROJECT_DIR$/Gemfile">
|
461
462
|
<provider selected="true" editor-type-id="text-editor">
|
462
|
-
<state line="
|
463
|
+
<state line="17" column="0" selection-start="412" selection-end="412" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="345">
|
464
|
+
<folding />
|
465
|
+
</state>
|
466
|
+
</provider>
|
467
|
+
</entry>
|
468
|
+
<entry file="file://$PROJECT_DIR$/Rakefile">
|
469
|
+
<provider selected="true" editor-type-id="text-editor">
|
470
|
+
<state line="8" column="3" selection-start="125" selection-end="125" vertical-scroll-proportion="0.121703856" vertical-offset="0" max-vertical-offset="1035">
|
463
471
|
<folding />
|
464
472
|
</state>
|
465
473
|
</provider>
|
466
474
|
</entry>
|
467
475
|
<entry file="file://$PROJECT_DIR$/lib/deep_dive/deep_dive.rb">
|
468
476
|
<provider selected="true" editor-type-id="text-editor">
|
469
|
-
<state line="
|
477
|
+
<state line="54" column="70" selection-start="1678" selection-end="1678" vertical-scroll-proportion="0.0" vertical-offset="632" max-vertical-offset="2100">
|
470
478
|
<folding />
|
471
479
|
</state>
|
472
480
|
</provider>
|
473
481
|
</entry>
|
474
482
|
<entry file="file://$PROJECT_DIR$/deep_dive.gemspec">
|
475
483
|
<provider selected="true" editor-type-id="text-editor">
|
476
|
-
<state line="
|
484
|
+
<state line="28" column="26" selection-start="1199" selection-end="1199" vertical-scroll-proportion="0.4259635" vertical-offset="0" max-vertical-offset="1230">
|
477
485
|
<folding />
|
478
486
|
</state>
|
479
487
|
</provider>
|
480
488
|
</entry>
|
481
|
-
<entry file="file://$PROJECT_DIR$/
|
489
|
+
<entry file="file://$PROJECT_DIR$/spec/lib/deep_dive/deep_dive_spec.rb">
|
482
490
|
<provider selected="true" editor-type-id="text-editor">
|
483
|
-
<state line="
|
491
|
+
<state line="34" column="0" selection-start="357" selection-end="770" vertical-scroll-proportion="0.0" vertical-offset="45" max-vertical-offset="1410">
|
484
492
|
<folding />
|
485
493
|
</state>
|
486
494
|
</provider>
|
487
495
|
</entry>
|
488
|
-
<entry file="file://$PROJECT_DIR$/
|
496
|
+
<entry file="file://$PROJECT_DIR$/README.rdoc">
|
489
497
|
<provider selected="true" editor-type-id="text-editor">
|
490
|
-
<state line="
|
498
|
+
<state line="56" column="0" selection-start="1693" selection-end="1693" vertical-scroll-proportion="0.851927" vertical-offset="0" max-vertical-offset="1065">
|
491
499
|
<folding />
|
492
500
|
</state>
|
493
501
|
</provider>
|
data/.semver
CHANGED
data/README.rdoc
CHANGED
@@ -11,15 +11,52 @@ copying of your complex interconnected objects.
|
|
11
11
|
Simply include DeepDive in your base class. All classes derived will be set
|
12
12
|
for deep cloning or deep duping.
|
13
13
|
|
14
|
-
==
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
== Examples
|
15
|
+
|
16
|
+
class FooBase
|
17
|
+
include DeepDive
|
18
|
+
exclude :c
|
19
|
+
end
|
20
|
+
|
21
|
+
Even though the instance variable @c is not defined in the base class, any instance
|
22
|
+
variables with that name in the subclasses will be excluded from the deep clone or duping.
|
23
|
+
It will simply use the reference to that object instead (a.k.a shallow copying)
|
24
|
+
|
25
|
+
class Foo < FooBase
|
26
|
+
attr_accessor :a, :b, :c, :changeme
|
27
|
+
end
|
28
|
+
|
29
|
+
class Bar < FooBase
|
30
|
+
attr_accessor :a, :b, :c, :changeme
|
31
|
+
end
|
32
|
+
|
33
|
+
class FooBar < FooBase
|
34
|
+
attr_accessor :a, :b, :c, :changeme, :dontcopy, :arr, :hsh, :nonddob
|
35
|
+
exclude :dontcopy
|
36
|
+
end
|
37
|
+
|
38
|
+
@foo = Foo.new
|
39
|
+
@bar = Bar.new
|
40
|
+
@foobar = FooBar.new
|
41
|
+
@foobar.arr = [@foo, @bar, @foobar, "Just a string"]
|
42
|
+
@foobar.hsh = {foo: @foo, bar: @bar, foobar: @foobar, nonddob: "just a string"}
|
43
|
+
|
44
|
+
@foo.a = 'foo just around'
|
45
|
+
@bar.a = 'bar hanging around'
|
46
|
+
@foo.b = @bar
|
47
|
+
@bar.b = @foo
|
48
|
+
@foo.c = @bar.c = @foobar.c = @foobar
|
49
|
+
@foo.changeme = @bar.changeme = @foobar.changeme = "initial"
|
50
|
+
|
51
|
+
So now if you do:
|
52
|
+
|
53
|
+
nfoo = @foo.dclone
|
54
|
+
|
55
|
+
@foo.c will refer to the same object as nfoo.c,
|
56
|
+
but @foo.b and nfoo.b will be different, as nfoo.b will be a clone of @foo.b.
|
57
|
+
|
58
|
+
Please see spec/lib/deep_dive/deep_dive_spec.rb for a more comprehensve example
|
59
|
+
of the above. Better documentation will be supplied shortly.
|
23
60
|
|
24
61
|
== Copyright
|
25
62
|
|
data/deep_dive.gemspec
CHANGED
data/lib/deep_dive/deep_dive.rb
CHANGED
@@ -52,6 +52,15 @@ module DeepDive
|
|
52
52
|
# For all enumerable objects, we will have to handle their situation
|
53
53
|
# differently.
|
54
54
|
module ::Enumerable
|
55
|
+
# FIXME: clean up the code a bit, this could be better structured.
|
56
|
+
def _ob_maybe_repl(v: nil, dupit: nil, oc: nil)
|
57
|
+
if v.respond_to? :_replicate
|
58
|
+
v._replicate(oc: oc, dupit: dupit)
|
59
|
+
else
|
60
|
+
v
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
55
64
|
# add a single element to the enumerable.
|
56
65
|
# You may pass a single parameter, or a key, value. In any case,
|
57
66
|
# all will added.
|
@@ -64,12 +73,12 @@ module DeepDive
|
|
64
73
|
case
|
65
74
|
when self.kind_of?(Set)
|
66
75
|
when self.kind_of?(Array)
|
67
|
-
self << v
|
76
|
+
self << _ob_maybe_repl(v: v, dupit: dupit, oc: oc)
|
68
77
|
else
|
69
78
|
raise DeepDiveException.new("Don't know how to add new elements for class #{self.class}")
|
70
79
|
end
|
71
80
|
else
|
72
|
-
self[v.first] = v
|
81
|
+
self[v.first] = _ob_maybe_repl(v: v, dupit: dupit, oc: oc)
|
73
82
|
end
|
74
83
|
end
|
75
84
|
|
@@ -14,7 +14,7 @@ class Bar < FooBase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class FooBar < FooBase
|
17
|
-
attr_accessor :a, :b, :c, :changeme, :dontcopy, :arr, :hsh
|
17
|
+
attr_accessor :a, :b, :c, :changeme, :dontcopy, :arr, :hsh, :nonddob
|
18
18
|
exclude :dontcopy
|
19
19
|
end
|
20
20
|
|
@@ -23,8 +23,8 @@ describe DeepDive do
|
|
23
23
|
@foo = Foo.new
|
24
24
|
@bar = Bar.new
|
25
25
|
@foobar = FooBar.new
|
26
|
-
@foobar.arr = [@foo, @bar, @foobar]
|
27
|
-
@foobar.hsh = {foo: @foo, bar: @bar, foobar: @foobar}
|
26
|
+
@foobar.arr = [@foo, @bar, @foobar, "Just a string"]
|
27
|
+
@foobar.hsh = {foo: @foo, bar: @bar, foobar: @foobar, nonddob: "just a string"}
|
28
28
|
|
29
29
|
@foo.a = 'foo just around'
|
30
30
|
@bar.a = 'bar hanging around'
|
@@ -71,7 +71,9 @@ describe DeepDive do
|
|
71
71
|
cfb.arr.size.should > 0
|
72
72
|
(0 ... cfb.arr.size).each do |i|
|
73
73
|
cfb.arr[i].should_not be_nil
|
74
|
-
|
74
|
+
if @foobar.arr[i].respond_to? :_replicate
|
75
|
+
cfb.arr[i].should_not == @foobar.arr[i]
|
76
|
+
end
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|