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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e99a4fcfbd4ca7a9a15b989359217248f1b570b
4
- data.tar.gz: f5102c60b3bdcb53ade0e8c66367eed6827979e8
3
+ metadata.gz: d9b53f0db147c075992df86e4800da412bc39d2f
4
+ data.tar.gz: 5df897b75bddf97278a92b7674e6aa5dfc4b0c00
5
5
  SHA512:
6
- metadata.gz: 99c6d1f3a285dfe3934cd432060a77086ee0fa3a17fce84d9dee51b7a395e8fa5b19cc32e42f1bb5d7376dc58c9cc5881a765c7755a7f25cf35424f988f23276
7
- data.tar.gz: ee1dc77cb3a9766eb5f628fc666afe5839a319c48d7632ed63b24d3d1c178b1c62631e99e0aead5fed9103202712c4bad4d0b902d4ca9336c4472b08b9a06ef2
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="1" column="25" selection-start="13" selection-end="44" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="1965">
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" column="31" selection-start="1740" selection-end="1740" vertical-scroll-proportion="0.74543613" vertical-offset="0" max-vertical-offset="1230">
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="Rakefile" pinned="false" current="true" current-in-tab="true">
60
- <entry file="file://$PROJECT_DIR$/Rakefile">
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="19" column="17" selection-start="352" selection-end="352" vertical-scroll-proportion="0.28904665" vertical-offset="0" max-vertical-offset="1035">
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="README.rdoc" pinned="false" current="false" current-in-tab="false">
69
- <entry file="file://$PROJECT_DIR$/README.rdoc">
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="28" column="0" selection-start="1336" selection-end="1336" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="510">
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.2497332" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
384
- <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.2497332" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
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$/README.rdoc">
454
+ <entry file="file://$PROJECT_DIR$/.semver">
454
455
  <provider selected="true" editor-type-id="text-editor">
455
- <state line="28" column="0" selection-start="1336" selection-end="1336" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="510">
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$/.semver">
461
+ <entry file="file://$PROJECT_DIR$/Gemfile">
461
462
  <provider selected="true" editor-type-id="text-editor">
462
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="999">
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="1" column="25" selection-start="13" selection-end="44" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="1965">
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="49" column="31" selection-start="1740" selection-end="1740" vertical-scroll-proportion="0.74543613" vertical-offset="0" max-vertical-offset="1230">
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$/Gemfile">
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="17" column="0" selection-start="412" selection-end="412" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="345">
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$/Rakefile">
496
+ <entry file="file://$PROJECT_DIR$/README.rdoc">
489
497
  <provider selected="true" editor-type-id="text-editor">
490
- <state line="19" column="17" selection-start="352" selection-end="352" vertical-scroll-proportion="0.28904665" vertical-offset="0" max-vertical-offset="1035">
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
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 2
4
+ :patch: 4
5
5
  :special: ''
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
- == Contributing to deep_dive
15
-
16
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
17
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
18
- * Fork the project.
19
- * Start a feature/bugfix branch.
20
- * Commit and push until you are happy with your contribution.
21
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
22
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "deep_dive"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Fred Mitchell"]
@@ -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._replicate(oc: oc, dupit: dupit)
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.last._replicate(oc: oc, dupit: dupit)
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
- cfb.arr[i].should_not == @foobar.arr[i]
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_dive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Mitchell