set_sync 0.0.2 → 0.0.3

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 (2) hide show
  1. data/lib/set_sync.rb +45 -6
  2. metadata +2 -2
data/lib/set_sync.rb CHANGED
@@ -1,13 +1,39 @@
1
1
  require 'set'
2
2
  class SetSync
3
- attr_accessor :local_binding, :remote_binding
4
3
 
4
+ class << self
5
+ def local_binding(binding=nil)
6
+ if binding
7
+ @local_binding = binding
8
+ else
9
+ @local_binding
10
+ end
11
+ end
12
+ def remote_binding(binding=nil)
13
+ if binding
14
+ @remote_binding = binding
15
+ else
16
+ @remote_binding
17
+ end
18
+ end
19
+ def on_enter(&blk)
20
+ blk ? @on_enter=blk : @on_enter
21
+ end
22
+ def on_exit(&blk)
23
+ blk ? @on_exit=blk : @on_enter
24
+ end
25
+ def on_update(&blk)
26
+ blk ? @on_update=blk : @on_update
27
+ end
28
+ end
29
+
30
+ attr_accessor :local_binding, :remote_binding
5
31
  def initialize(local, remote, options={}, &blk)
6
32
  @local = local
7
33
  @remote = remote
8
34
 
9
- @local_binding = options[:local_binding] || :id
10
- @remote_binding = options[:remote_binding] || :id
35
+ @local_binding = options[:local_binding] || self.class.local_binding || :id
36
+ @remote_binding = options[:remote_binding] || self.class.remote_binding || :id
11
37
 
12
38
  sync_block(blk) if blk
13
39
  end
@@ -53,22 +79,35 @@ class SetSync
53
79
 
54
80
  def do_entering
55
81
  entering.each do |binding|
56
- @on_enter.call remote_hash[binding]
82
+ do_enter remote_hash[binding]
57
83
  end
58
84
  end
59
85
 
60
86
  def do_exiting
61
87
  exiting.each do |binding|
62
- @on_exit.call local_hash[binding]
88
+ do_exit local_hash[binding]
63
89
  end
64
90
  end
65
91
 
66
92
  def do_updating
67
93
  updating.each do |binding|
68
- @on_update.call local_hash[binding], remote_hash[binding]
94
+ do_update local_hash[binding], remote_hash[binding]
69
95
  end
70
96
  end
71
97
 
98
+ def do_enter(remote)
99
+ blk = @on_enter || self.class.on_enter
100
+ blk.call remote
101
+ end
102
+ def do_exit(local)
103
+ blk = @on_exit || self.class.on_exit
104
+ blk.call local
105
+ end
106
+ def do_update(local, remote)
107
+ blk = @on_update || self.class.on_update
108
+ blk.call local, remote
109
+ end
110
+
72
111
  def on_enter(&blk)
73
112
  @on_enter = blk
74
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: set_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-31 00:00:00.000000000 Z
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Syncs sets
15
15
  email: phil@latentflip.com