gibbler 0.7.1 → 0.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/CHANGES.txt CHANGED
@@ -1,6 +1,14 @@
1
1
  GIBBLER, CHANGES
2
2
 
3
3
 
4
+ #### 0.7.2 (2009-12-08) #################################
5
+
6
+ * FIXED: Gibbler::Complex no longer includes the '@' for instance
7
+ variable names used in digest calculation.
8
+ * ADDED: Gibbler::Complex support for specifying which fields
9
+ to use in digest calculation.
10
+
11
+
4
12
  #### 0.7.1 (2009-10-09) #################################
5
13
 
6
14
  * FIXED: Gibbler::Complex now sorts instance variables before processing.
data/gibbler.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "gibbler"
3
3
  s.rubyforge_project = "gibbler"
4
- s.version = "0.7.1"
4
+ s.version = "0.7.2"
5
5
  s.summary = "Gibbler: Git-like hashes for Ruby objects"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -6,6 +6,8 @@ module Gibbler
6
6
  module Object
7
7
  alias :digest :gibbler
8
8
  alias :changed? :gibbled?
9
+ alias :digest_fields :gibbler_fields
10
+
9
11
  # The cache is in the Attic.
10
12
  def digest_cache; gibbler_cache; end
11
13
  end
data/lib/gibbler.rb CHANGED
@@ -1,3 +1,10 @@
1
+ unless defined?(GIBBLER_LIB_HOME)
2
+ GIBBLER_LIB_HOME = File.expand_path File.dirname(__FILE__)
3
+ end
4
+
5
+ %w{attic}.each do |dir|
6
+ $:.unshift File.join(GIBBLER_LIB_HOME, '..', '..', dir, 'lib')
7
+ end
1
8
 
2
9
  require 'thread'
3
10
  require 'attic'
@@ -8,7 +15,7 @@ require 'digest/sha1'
8
15
  # "Hola, Tanneritos"
9
16
  #
10
17
  module Gibbler
11
- VERSION = "0.7.1"
18
+ VERSION = "0.7.2"
12
19
 
13
20
  require 'gibbler/mixins'
14
21
 
@@ -92,6 +99,11 @@ module Gibbler
92
99
  obj.send :alias_method, :__gibbler_cache, :gibbler_cache
93
100
  end
94
101
 
102
+ def self.gibbler_fields
103
+ end
104
+ def gibbler_fields
105
+ end
106
+
95
107
  # Calculates a digest for the current object instance.
96
108
  # Objects that are a kind of Hash or Array are processed
97
109
  # recursively. The length of the returned String depends
@@ -231,15 +243,42 @@ module Gibbler
231
243
  def self.included(obj)
232
244
  obj.extend Attic
233
245
  obj.attic :gibbler_cache
246
+ obj.class_eval do
247
+ @__gibbler_fields = []
248
+ def self.gibbler_fields
249
+ @__gibbler_fields
250
+ end
251
+ def self.gibbler *fields
252
+ @__gibbler_fields = *fields
253
+ end
254
+ def self.inherited(obj)
255
+ obj.extend Attic
256
+ obj.attic :gibbler_cache
257
+ fields = @__gibbler_fields.clone
258
+ obj.class_eval do
259
+ @__gibbler_fields = fields
260
+ end
261
+ end
262
+ end
263
+ end
264
+
265
+ def gibbler_fields
266
+ f = self.class.gibbler_fields
267
+ if f.empty?
268
+ f = instance_variables.sort.collect { |n|
269
+ n.to_s[1..-1].to_sym # remove the '@'
270
+ }
271
+ end
272
+ f
234
273
  end
235
274
 
236
275
  # Creates a digest for the current state of self.
237
276
  def __gibbler(h=self)
238
277
  klass = h.class
239
278
  d = []
240
- gibbler_debug :ivars, instance_variables.sort
241
- instance_variables.sort.each do |n|
242
- value = instance_variable_get(n)
279
+ gibbler_debug :gibbler_fields, gibbler_fields
280
+ gibbler_fields.each do |n|
281
+ value = instance_variable_get("@#{n}")
243
282
  d << '%s:%s:%s' % [value.class, n, value.__gibbler]
244
283
  end
245
284
  d = d.join(':').__gibbler
@@ -359,17 +398,12 @@ module Gibbler
359
398
  # Creates a digest for the current state of self.
360
399
  def __gibbler(h=self)
361
400
  klass = h.class
362
- d, idx = [], 0
363
- shorts = ['String', 'Fixnum', 'Symbol']
364
- h.each do |v| # Some Array-like classes don't have each_with_index
365
- if shorts.member?(v.class.to_s)
366
- d << '%s:%s:%s:%s' % [v.class, idx, v.to_s.size, v.to_s]
367
- else
368
- d << '%s:%s:%s' % [v.class, idx, v.__gibbler]
369
- end
370
- idx += 1
401
+ d, index = [], 0
402
+ h.each do |value|
403
+ d << '%s:%s:%s' % [value.class, index, value.__gibbler]
404
+ index += 1
371
405
  end
372
- d = d.join(':')
406
+ d = d.join(':').__gibbler
373
407
  a = Gibbler.digest '%s:%s:%s' % [klass, d.size, d]
374
408
  gibbler_debug klass, a, [klass, d.size, d]
375
409
  a
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-23 00:00:00 -05:00
12
+ date: 2009-12-09 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency