simplesync 0.0.2

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.
Files changed (53) hide show
  1. data/LICENSE +16 -0
  2. data/README +40 -0
  3. data/Rakefile +78 -0
  4. data/doc/classes/Hash.html +153 -0
  5. data/doc/classes/Hash.src/M000001.html +28 -0
  6. data/doc/classes/SimpleSync.html +121 -0
  7. data/doc/classes/SimpleSync/Mappings.html +169 -0
  8. data/doc/classes/SimpleSync/Mappings.src/M000026.html +19 -0
  9. data/doc/classes/SimpleSync/Mappings.src/M000027.html +20 -0
  10. data/doc/classes/SimpleSync/Record.html +188 -0
  11. data/doc/classes/SimpleSync/Record.src/M000002.html +22 -0
  12. data/doc/classes/SimpleSync/Record.src/M000003.html +23 -0
  13. data/doc/classes/SimpleSync/Record.src/M000004.html +25 -0
  14. data/doc/classes/SimpleSync/RecordSet.html +235 -0
  15. data/doc/classes/SimpleSync/RecordSet.src/M000028.html +23 -0
  16. data/doc/classes/SimpleSync/RecordSet.src/M000029.html +18 -0
  17. data/doc/classes/SimpleSync/RecordSet.src/M000030.html +19 -0
  18. data/doc/classes/SimpleSync/RecordSet.src/M000031.html +20 -0
  19. data/doc/classes/SimpleSync/RecordSet.src/M000032.html +18 -0
  20. data/doc/classes/SimpleSync/Source.html +356 -0
  21. data/doc/classes/SimpleSync/Source.src/M000005.html +19 -0
  22. data/doc/classes/SimpleSync/Source.src/M000006.html +19 -0
  23. data/doc/classes/SimpleSync/Source.src/M000007.html +19 -0
  24. data/doc/classes/SimpleSync/Source.src/M000008.html +22 -0
  25. data/doc/classes/SimpleSync/Source.src/M000009.html +18 -0
  26. data/doc/classes/SimpleSync/Source.src/M000010.html +20 -0
  27. data/doc/classes/SimpleSync/Source.src/M000011.html +22 -0
  28. data/doc/classes/SimpleSync/Source.src/M000012.html +18 -0
  29. data/doc/classes/SimpleSync/Source.src/M000013.html +18 -0
  30. data/doc/classes/SimpleSync/Syncer.html +408 -0
  31. data/doc/classes/SimpleSync/Syncer.src/M000014.html +18 -0
  32. data/doc/classes/SimpleSync/Syncer.src/M000015.html +18 -0
  33. data/doc/classes/SimpleSync/Syncer.src/M000016.html +18 -0
  34. data/doc/classes/SimpleSync/Syncer.src/M000017.html +18 -0
  35. data/doc/classes/SimpleSync/Syncer.src/M000018.html +18 -0
  36. data/doc/classes/SimpleSync/Syncer.src/M000019.html +18 -0
  37. data/doc/classes/SimpleSync/Syncer.src/M000020.html +18 -0
  38. data/doc/classes/SimpleSync/Syncer.src/M000021.html +18 -0
  39. data/doc/classes/SimpleSync/Syncer.src/M000022.html +35 -0
  40. data/doc/classes/SimpleSync/Syncer.src/M000023.html +44 -0
  41. data/doc/classes/SimpleSync/Syncer.src/M000024.html +41 -0
  42. data/doc/classes/SimpleSync/Syncer.src/M000025.html +25 -0
  43. data/doc/created.rid +1 -0
  44. data/doc/files/LICENSE.html +129 -0
  45. data/doc/files/README.html +155 -0
  46. data/doc/files/lib/simple_sync_rb.html +107 -0
  47. data/doc/fr_class_index.html +33 -0
  48. data/doc/fr_file_index.html +29 -0
  49. data/doc/fr_method_index.html +58 -0
  50. data/doc/index.html +24 -0
  51. data/doc/rdoc-style.css +208 -0
  52. data/lib/simple_sync.rb +387 -0
  53. metadata +115 -0
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 8</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">last_sync</span>)
15
+ <span class="ruby-ivar">@last_sync</span> = <span class="ruby-identifier">last_sync</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>sources (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 13</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sources</span>
15
+ <span class="ruby-ivar">@sources</span> <span class="ruby-operator">||=</span> []
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>mappings (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 18</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mappings</span>
15
+ <span class="ruby-ivar">@mappings</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Mappings</span>.<span class="ruby-identifier">new</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>add_source (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 24</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_source</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">identifier</span>, <span class="ruby-identifier">finder_scope</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
15
+ (<span class="ruby-identifier">block_given?</span> <span class="ruby-value">? </span>(<span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Source</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">identifier</span>, <span class="ruby-identifier">mappings</span>, <span class="ruby-identifier">finder_scope</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)) <span class="ruby-operator">:</span> (<span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Source</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">identifier</span>, <span class="ruby-identifier">mappings</span>, <span class="ruby-identifier">finder_scope</span>)))[<span class="ruby-value">-1</span>]
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new_records (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 29</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_records</span>
15
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">new_records</span>.<span class="ruby-identifier">set</span>}.<span class="ruby-identifier">flatten</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>changed_records (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 33</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">changed_records</span>
15
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">changed_records</span>.<span class="ruby-identifier">set</span>}.<span class="ruby-identifier">flatten</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>deleted_records (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 37</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deleted_records</span>
15
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">deleted_records</span>.<span class="ruby-identifier">set</span>}.<span class="ruby-identifier">flatten</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>snapshot! (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 47</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">snapshot!</span>
15
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">snapshot!</span>}
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>sync_deleted! (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 55</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sync_deleted!</span>
15
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">source</span><span class="ruby-operator">|</span>
16
+ <span class="ruby-identifier">source</span>.<span class="ruby-identifier">deleted_records</span>.<span class="ruby-identifier">snapshot!</span>
17
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Deleting #{source.deleted_records.length} records that were deleted on #{source.name}...&quot;</span>
18
+ <span class="ruby-identifier">source</span>.<span class="ruby-identifier">deleted_records</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sourcerec</span><span class="ruby-operator">|</span>
19
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">except</span>(<span class="ruby-identifier">source</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">target</span><span class="ruby-operator">|</span>
20
+ <span class="ruby-comment cmt"># Some of these may already be deleted on the other sources. (Especially if we've synced within the last sync time already.)</span>
21
+ <span class="ruby-comment cmt"># If the record exists on the source,</span>
22
+ <span class="ruby-identifier">targetrec</span> = <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">find_on</span>(<span class="ruby-identifier">target</span>)
23
+ <span class="ruby-comment cmt"># delete it.</span>
24
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">targetrec</span>
25
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tDeleting #{sourcerec.identifier} -&gt; #{targetrec.identifier} on #{target.name}&quot;</span>
26
+ <span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">delete</span>
27
+ <span class="ruby-keyword kw">else</span>
28
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tSkipped #{sourcerec.identifier} on #{target.name}&quot;</span>
29
+ <span class="ruby-keyword kw">end</span>
30
+ <span class="ruby-keyword kw">end</span>
31
+ <span class="ruby-keyword kw">end</span>
32
+ <span class="ruby-keyword kw">end</span>
33
+ <span class="ruby-keyword kw">end</span></pre>
34
+ </body>
35
+ </html>
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>sync_new! (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 80</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sync_new!</span>
15
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">source</span><span class="ruby-operator">|</span>
16
+ <span class="ruby-identifier">source</span>.<span class="ruby-identifier">new_records</span>.<span class="ruby-identifier">snapshot!</span>
17
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Creating #{source.new_records.length} records that were created on #{source.name}...&quot;</span>
18
+ <span class="ruby-identifier">source</span>.<span class="ruby-identifier">new_records</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sourcerec</span><span class="ruby-operator">|</span>
19
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">except</span>(<span class="ruby-identifier">source</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">target</span><span class="ruby-operator">|</span>
20
+ <span class="ruby-comment cmt"># Need to weed out the ones that were already created</span>
21
+ <span class="ruby-identifier">targetrec</span> = <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">find_on</span>(<span class="ruby-identifier">target</span>)
22
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">targetrec</span>
23
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tSkipped #{sourcerec.identifier} -&gt; #{targetrec.identifier} on #{target.name}&quot;</span>
24
+ <span class="ruby-keyword kw">else</span>
25
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">targetrec</span> = <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">morph_to</span>(<span class="ruby-identifier">target</span>)).<span class="ruby-identifier">save</span>
26
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tCreated #{sourcerec.identifier} -&gt; #{targetrec.identifier} on #{target.name}&quot;</span>
27
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">morph_to</span>(<span class="ruby-identifier">target</span>).<span class="ruby-identifier">morph_to</span>(<span class="ruby-identifier">source</span>).<span class="ruby-identifier">to_hash</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">morph_to</span>(<span class="ruby-identifier">source</span>).<span class="ruby-identifier">to_hash</span>
28
+ <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">data</span> = <span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">morph_to</span>(<span class="ruby-identifier">source</span>).<span class="ruby-identifier">to_hash</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">nil?</span>}
29
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">save</span>
30
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\t -&gt; Saved record relationship #{sourcerec.identifier} -&gt; #{targetrec.identifier}.&quot;</span>
31
+ <span class="ruby-keyword kw">else</span>
32
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\t -&gt; PROBLEM SAVING record relationship #{sourcerec.identifier} -&gt; #{targetrec.identifier} !&quot;</span>
33
+ <span class="ruby-keyword kw">end</span>
34
+ <span class="ruby-keyword kw">end</span>
35
+ <span class="ruby-keyword kw">else</span>
36
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tPROBLEM SAVING #{sourcerec.identifier} on #{target.name} !&quot;</span>
37
+ <span class="ruby-keyword kw">end</span>
38
+ <span class="ruby-keyword kw">end</span>
39
+ <span class="ruby-keyword kw">end</span>
40
+ <span class="ruby-keyword kw">end</span>
41
+ <span class="ruby-keyword kw">end</span>
42
+ <span class="ruby-keyword kw">end</span></pre>
43
+ </body>
44
+ </html>
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>sync_changed! (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 113</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sync_changed!</span>
15
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">source</span><span class="ruby-operator">|</span>
16
+ <span class="ruby-identifier">source</span>.<span class="ruby-identifier">changed_records</span>.<span class="ruby-identifier">snapshot!</span>
17
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Updating #{source.changed_records.length} records that were updated on #{source.name}...&quot;</span>
18
+ <span class="ruby-identifier">source</span>.<span class="ruby-identifier">changed_records</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sourcerec</span><span class="ruby-operator">|</span>
19
+ <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">except</span>(<span class="ruby-identifier">source</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">target</span><span class="ruby-operator">|</span>
20
+ <span class="ruby-comment cmt"># 1) Get the same record from the target</span>
21
+ <span class="ruby-identifier">targetrec</span> = <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">find_on</span>(<span class="ruby-identifier">target</span>)
22
+ <span class="ruby-comment cmt"># 2) Update the attributes</span>
23
+ <span class="ruby-identifier">target_update</span> = <span class="ruby-identifier">sourcerec</span>.<span class="ruby-identifier">morph_to</span>(<span class="ruby-identifier">target</span>).<span class="ruby-identifier">to_hash</span>.<span class="ruby-identifier">reject</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">mappings</span>[<span class="ruby-identifier">target</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">source</span>].<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">k</span>) }
24
+ <span class="ruby-identifier">target_attrs</span> = <span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">to_hash</span>.<span class="ruby-identifier">reject</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">target_update</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">k</span>)}
25
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">target_update</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">target_update</span> <span class="ruby-comment cmt"># If any data was actually changed.</span>
26
+ <span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">update_data</span>(<span class="ruby-identifier">target_update</span>)
27
+ <span class="ruby-comment cmt"># 3) Save the target record</span>
28
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">save</span>
29
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tUpdated #{sourcerec.identifier} -&gt; #{targetrec.identifier} on #{target.name}&quot;</span>
30
+ <span class="ruby-keyword kw">else</span>
31
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tPROBLEM SAVING #{sourcerec.identifier} -&gt; #{targetrec.identifier} on #{target.name}&quot;</span><span class="ruby-operator">+</span>(<span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:error</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">targetrec</span>.<span class="ruby-identifier">error</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-value str">''</span>)
32
+ <span class="ruby-keyword kw">end</span>
33
+ <span class="ruby-keyword kw">else</span>
34
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\tNo changes mapped from #{sourcerec.identifier} -&gt; #{targetrec.identifier} on #{target.name}&quot;</span>
35
+ <span class="ruby-keyword kw">end</span>
36
+ <span class="ruby-keyword kw">end</span>
37
+ <span class="ruby-keyword kw">end</span>
38
+ <span class="ruby-keyword kw">end</span>
39
+ <span class="ruby-keyword kw">end</span></pre>
40
+ </body>
41
+ </html>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>sync! (SimpleSync::Syncer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/simple_sync.rb, line 143</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sync!</span>
15
+ <span class="ruby-comment cmt"># To sync, we have all the tools, here comes the magic!</span>
16
+ <span class="ruby-comment cmt"># 1) Sync DELETED.</span>
17
+ <span class="ruby-identifier">sync_deleted!</span>
18
+ <span class="ruby-comment cmt"># 2) Sync NEW.</span>
19
+ <span class="ruby-identifier">sync_new!</span>
20
+ <span class="ruby-comment cmt"># 3) Sync CHANGED.</span>
21
+ <span class="ruby-identifier">sync_changed!</span>
22
+ <span class="ruby-ivar">@last_sync</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
23
+ <span class="ruby-keyword kw">end</span></pre>
24
+ </body>
25
+ </html>
@@ -0,0 +1 @@
1
+ Thu, 20 Mar 2008 16:56:30 -0400
@@ -0,0 +1,129 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: LICENSE</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>LICENSE</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>LICENSE
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Tue Mar 18 01:40:07 -0400 2008</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+ <div id="description">
72
+ <p>
73
+ Copyright (c) 2008 BehindLogic
74
+ </p>
75
+ <p>
76
+ Permission is hereby granted, free of charge, to any person obtaining a
77
+ copy of this software and associated documentation files (the
78
+ &quot;Software&quot;), to deal in the Software without restriction,
79
+ including without limitation the rights to use, copy, modify, merge,
80
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
81
+ permit persons to whom the Software is furnished to do so, subject to the
82
+ following conditions:
83
+ </p>
84
+ <p>
85
+ The above copyright notice and this permission notice shall be included in
86
+ all copies or substantial portions of the Software.
87
+ </p>
88
+ <p>
89
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
90
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
91
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
92
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
93
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
94
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
95
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
96
+ </p>
97
+
98
+ </div>
99
+
100
+
101
+ </div>
102
+
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+
109
+ <div id="section">
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ <!-- if method_list -->
119
+
120
+
121
+ </div>
122
+
123
+
124
+ <div id="validator-badges">
125
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
126
+ </div>
127
+
128
+ </body>
129
+ </html>
@@ -0,0 +1,155 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: README</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>README</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>README
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Tue Mar 18 01:39:39 -0400 2008</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+ <div id="description">
72
+ <h2><a href="../classes/SimpleSync.html">SimpleSync</a></h2>
73
+ <p>
74
+ The purpose of this gem is to provide a body that can perform the
75
+ synchronization necessary when given the right inputs.
76
+ </p>
77
+ <p>
78
+ It is based on the idea that synchronization is a combination of: 1) data
79
+ sources, 2) records, 3) attribute mappings, and 4) synchronization logic.
80
+ This gem encapsulates all of these so that you don&#8216;t have to worry
81
+ about how they relate to each other &#8212; only about defining what they
82
+ are. You initialize your data sources, define how to find the relevant
83
+ records, define how to map attributes between sources, and provide methods
84
+ on your source that can be used to get and save records. See the example
85
+ code:
86
+ </p>
87
+ <pre>
88
+ @sync = SimpleSync::Syncer.new(Time.now - 30*24*60*60)
89
+
90
+ @local = @sync.add_source(Person, :local, :external_id) {@adapter = :local}.extended(@sync) do |s|
91
+ new_records {Person.get(:adapter =&gt; :local, :created_after =&gt; s.last_sync)}
92
+ changed_records {Person.get(:adapter =&gt; :local, :updated_after =&gt; s.last_sync)}
93
+ deleted_records {DeletedRecord.get(:adapter =&gt; :local, :object_type =&gt; 'Person', :deleted_after =&gt; s.last_sync)}
94
+ end
95
+
96
+ @remote = @sync.add_source(Person, :remote, :self) {@adapter = :opcon_local}.extended(@sync) do |s|
97
+ new_records {Person.get(:adapter =&gt; :remote, :created_after =&gt; s.last_sync)}
98
+ changed_records {Person.get(:adapter =&gt; :remote, :updated_after =&gt; s.last_sync)}
99
+ deleted_records {DeletedRecord.get(:adapter =&gt; :remote, :object_type =&gt; 'Person', :deleted_after =&gt; s.last_sync)}
100
+ end
101
+
102
+ # Mapping the attributes from one to the other.
103
+ @sync.mappings[@local =&gt; @remote] = {
104
+ 'first_name' =&gt; 'first_name',
105
+ 'last_name' =&gt; 'last_name',
106
+ 'company_name' =&gt; 'company_name',
107
+ 'birthdate' =&gt; 'birthdate',
108
+ }
109
+
110
+ # And the other direction -- usually just in invert.
111
+ @sync.mappings[@remote =&gt; @local] = @sync.mappings[@local =&gt; @remote].invert
112
+
113
+ # Now all we need to do is a simple loop where we sync and wait.
114
+ while(1)
115
+
116
+ puts &quot;[#{Time.now}] Beginning Sync&quot;
117
+ @sync.sync!
118
+ puts &quot;[#{Time.now}] Finished Syncing&quot;
119
+
120
+ sleep(30)
121
+ end
122
+ </pre>
123
+
124
+ </div>
125
+
126
+
127
+ </div>
128
+
129
+
130
+ </div>
131
+
132
+
133
+ <!-- if includes -->
134
+
135
+ <div id="section">
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+ <!-- if method_list -->
145
+
146
+
147
+ </div>
148
+
149
+
150
+ <div id="validator-badges">
151
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
152
+ </div>
153
+
154
+ </body>
155
+ </html>