git-ds 0.9.6.1 → 0.9.7.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.
data/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2011-06-15 : mkfs <mkfs@thoughtgang.org>
2
+ * Added clear_cache method to ModelItem
3
+
4
+ 2011-06-14 : mkfs <mkfs@thoughtgang.org>
5
+ * Fixed ModelItem#array_property and ts_property methods
6
+
7
+ 2011-06-13 : mkfs <mkfs@thoughtgang.org>
8
+ * Added publish/subscribe support to Database object
9
+ * Bumped gem version to 0.9.7
10
+
1
11
  2011-06-06 : mkfs <mkfs@thoughtgang.org>
2
12
  * Added runtime checks (and exceptions) for NULL bytes in path
3
13
 
@@ -43,6 +43,13 @@ Default is nil (i.e. let Git read actor from .git/config or ENV).
43
43
  =end
44
44
  attr_accessor :actor
45
45
 
46
+ =begin rdoc
47
+ Subcribers that are notified when the model is changed. This is a Hash of
48
+ an ident (e.g. a classname, UUID, or symbol) to a 2-element array:
49
+ a callback method and an (optional) object to pass with that method.
50
+ =end
51
+ attr_reader :subscribers
52
+
46
53
  =begin rdoc
47
54
  Return a connection to the Git DB.
48
55
  Creates the DB if it does not already exist.
@@ -67,6 +74,7 @@ Creates the DB if it does not already exist.
67
74
  end
68
75
 
69
76
  @actor = Grit::Actor.new(username, email) if username
77
+ @subscribers = {}
70
78
 
71
79
  end
72
80
 
@@ -145,6 +153,45 @@ actor=.
145
153
  self.actor = name ? Grit::Actor.new(name, (email ? email : '')) : nil
146
154
  end
147
155
 
156
+ # ----------------------------------------------------------------------
157
+ =begin rdoc
158
+ Subscribe to change notifications from the model. The provided callback will
159
+ be invoked whenever the model is modified (specifically, when an outer
160
+ Transaction or ExecCmd is completed).
161
+
162
+ A subscriber can use either block or argument syntax:
163
+
164
+ def func_cb(arg)
165
+ ...
166
+ end
167
+ model.subscribe( self.ident, arg, func_cb )
168
+
169
+ # block callback
170
+ model.subscribe( self.ident ) { ... }
171
+
172
+ # block callback where arg is specified in advance
173
+ model.subscribe( self.ident, arg ) { |arg| ... }
174
+ =end
175
+ def subscribe(ident, obj=nil, func=nil, &block)
176
+ cb = (block_given?) ? block : func
177
+ @subscribers[ident] = [cb, obj]
178
+ end
179
+
180
+ =begin rdoc
181
+ Notify all subscribers that a change has occurred.
182
+ =end
183
+ def notify
184
+ @subscribers.each { |ident, (block,obj)| block.call(obj) }
185
+ end
186
+
187
+ =begin rdoc
188
+ Unsubscribe from change notification.
189
+ =end
190
+ def unsubscribe(ident)
191
+ @subscribers.delete(ident)
192
+ end
193
+
194
+ # ----------------------------------------------------------------------
148
195
  =begin rdoc
149
196
  Execute a block in the context of the staging index.
150
197
 
@@ -183,6 +230,7 @@ See Transaction.
183
230
  end
184
231
  end
185
232
 
233
+ # ----------------------------------------------------------------------
186
234
  =begin rdoc
187
235
  Add files to the database. Calls exec to ensure that a write is not performed
188
236
  if a staging index already exists.
@@ -278,6 +326,7 @@ See Database#transaction .
278
326
  rv
279
327
  end
280
328
 
329
+ # ----------------------------------------------------------------------
281
330
  private
282
331
 
283
332
  =begin rdoc
@@ -98,6 +98,7 @@ Perform command.
98
98
  if not self.nested
99
99
  self.index.build
100
100
  commit
101
+ @database.notify
101
102
  end
102
103
 
103
104
  rv
@@ -349,6 +349,14 @@ Return Hash of cached property values.
349
349
  @property_cache ||= {}
350
350
  end
351
351
 
352
+ =begin rdoc
353
+ Clear all caches in ModelItem instance. In the base class, this just clears
354
+ the property cache.
355
+ =end
356
+ def clear_cache
357
+ property_cache.clear
358
+ end
359
+
352
360
  =begin rdoc
353
361
  Return the value of a specific property. If the proprty has not been set,
354
362
  nil is returned.
@@ -389,7 +397,11 @@ Convenience method for reading Time (aka timestamp) properties.
389
397
  =end
390
398
  def timestamp_property(name)
391
399
  val = property(name)
392
- val && (! val.empty?) ? property_cache[name] = Time.parse(val) : nil
400
+ if val && (not val.kind_of? Time)
401
+ val = (not val.empty?) ? Time.parse(val) : nil
402
+ property_cache[name] = val
403
+ end
404
+ val
393
405
  end
394
406
 
395
407
  alias :ts_property :timestamp_property
@@ -414,7 +426,11 @@ Classes which perform their own encoding can choose a different delimiter.
414
426
  =end
415
427
  def array_property(name, delim="\n")
416
428
  val = property(name)
417
- val ? (property_cache[name] = val.split(delim)) : nil
429
+ if val && (not val.kind_of? Array)
430
+ val = (val.empty?) ? [] : val.split(delim)
431
+ property_cache[name] = val
432
+ end
433
+ val
418
434
  end
419
435
 
420
436
  alias :a_property :array_property
@@ -0,0 +1,44 @@
1
+ =begin rdoc
2
+ Subcribers that are notified when the model is changed. This is a Hash of
3
+ an ident (e.g. a classname, UUID, or symbol) to a 2-element array:
4
+ a callback method and an (optional) object to pass with that method.
5
+ =end
6
+ attr_reader :subscribers
7
+
8
+ @subscribers = {}
9
+ =begin rdoc
10
+ Subscribe to change notifications from the model. The provided callback will
11
+ be invoked whenever the model is modified (specifically, when an outer
12
+ Transaction or ExecCmd is completed).
13
+
14
+ A subscriber can use either block or argument syntax:
15
+
16
+ def func_cb(arg)
17
+ ...
18
+ end
19
+ model.subscribe( self.ident, arg, func_cb )
20
+
21
+ # block callback
22
+ model.subscribe( self.ident ) { ... }
23
+
24
+ # block callback where arg is specified in advance
25
+ model.subscribe( self.ident, arg ) { |arg| ... }
26
+ =end
27
+ def subscribe(ident, obj=nil, func=nil, &block)
28
+ cb = (block_given?) ? block : func
29
+ @subscribers[ident] = [cb, obj]
30
+ end
31
+
32
+ =begin rdoc
33
+ Notify all subscribers that a change has occurred.
34
+ =end
35
+ def notify
36
+ @subscribers.each { |ident, (block,obj)} block.call(obj) }
37
+ end
38
+
39
+ =begin rdoc
40
+ Unsubscribe from change notification.
41
+ =end
42
+ def unsubscribe(ident)
43
+ @subscribers.delete(ident)
44
+ end
@@ -51,6 +51,7 @@ rollback() is called.
51
51
  if rv
52
52
  self.index.build # required during nesting to support merge_and_branch
53
53
  commit if not @nested
54
+ @database.notify if not @nested
54
55
  end
55
56
 
56
57
  rv
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-ds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6.1
4
+ version: 0.9.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-06 00:00:00.000000000 -04:00
12
+ date: 2011-06-15 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grit
17
- requirement: &14078760 !ruby/object:Gem::Requirement
17
+ requirement: &19273020 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 2.2.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *14078760
25
+ version_requirements: *19273020
26
26
  description: A hierarchical datastore based on Git.
27
27
  email: community@thoughtgang.org
28
28
  executables: []
@@ -58,6 +58,7 @@ extra_rdoc_files:
58
58
  - README.rdoc
59
59
  files:
60
60
  - lib/git-ds.rb
61
+ - lib/git-ds/t.rb
61
62
  - lib/git-ds/model.rb
62
63
  - lib/git-ds/exec_cmd.rb
63
64
  - lib/git-ds/config.rb