gibbler 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,6 +1,14 @@
1
1
  GIBBLER, CHANGES
2
2
 
3
3
 
4
+ #### 0.6.3 (2009-09-30) #################################
5
+
6
+ * FIXED: Won't save digest to cache if the object is frozen
7
+ * CHANGE: Renamed __gibbler_cache to gibbler_cache (with backwards compatability)
8
+ * CHANGE: Gibbler::Digest#== now returns true only for exact matches
9
+ * ADDED: Gibbler::Digest#shorter, Gibbler::Digest#tiny, Gibbler::Digest#===
10
+
11
+
4
12
  #### 0.6.2 (2009-09-15) #################################
5
13
 
6
14
  * FIXED: Enforce specific string format for Time objects. Fixes
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.6.2"
4
+ s.version = "0.6.3"
5
5
  s.summary = "Gibbler: Git-like hashes for Ruby objects"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -17,11 +17,47 @@ class Gibbler::Digest < String
17
17
  self[0..7]
18
18
  end
19
19
 
20
+ # Returns the first 6 characters of itself (the digest).
21
+ #
22
+ # e.g.
23
+ #
24
+ # "kimmy".gibbler # => c8027100ecc54945ab15ddac529230e38b1ba6a1
25
+ # "kimmy".gibbler.tiny # => c80271
26
+ #
27
+ def shorter
28
+ self[0..5]
29
+ end
20
30
 
21
- def ==(g)
22
- return true if self.to_s == g.to_s
23
- return true if self.short.to_s == g.to_s
31
+ # Returns the first 4 characters of itself (the digest).
32
+ #
33
+ # e.g.
34
+ #
35
+ # "kimmy".gibbler # => c8027100ecc54945ab15ddac529230e38b1ba6a1
36
+ # "kimmy".gibbler.tiny # => c802
37
+ #
38
+ def tiny
39
+ self[0..3]
40
+ end
41
+
42
+ # Returns true when +ali+ matches +self+
43
+ #
44
+ # "kimmy".gibbler == "c8027100ecc54945ab15ddac529230e38b1ba6a1" # => true
45
+ # "kimmy".gibbler == "c8027100" # => false
46
+ #
47
+ def ==(ali)
48
+ return true if self.to_s == ali.to_s
24
49
  false
25
50
  end
26
51
 
52
+ # Returns true when +g+ matches one of: +self+, +short+, +shorter+, +tiny+
53
+ #
54
+ # "kimmy".gibbler === "c8027100ecc54945ab15ddac529230e38b1ba6a1" # => true
55
+ # "kimmy".gibbler === "c8027100" # => true
56
+ # "kimmy".gibbler === "c80271" # => true
57
+ # "kimmy".gibbler === "c802" # => true
58
+ #
59
+ def ===(g)
60
+ return true if [to_s, short, shorter, tiny].member?(g.to_s)
61
+ false
62
+ end
27
63
  end
@@ -112,16 +112,16 @@ module Gibbler
112
112
  g = gibbler_find_long g
113
113
 
114
114
  # Do nothing if the given digest matches the current gibble.
115
- # NOTE: We use __gibbler b/c it doesn't update self.__gibbler_cache.
115
+ # NOTE: We use __gibbler b/c it doesn't update self.gibbler_cache.
116
116
  unless self.__gibbler == g
117
117
  @@mutex.synchronize {
118
118
  # Always make sure self.gibbler_digest is a Gibbler::Digest
119
- self.__gibbler_cache = g.is_a?(Gibbler::Digest) ? g : Gibbler::Digest.new(g)
119
+ self.gibbler_cache = g.is_a?(Gibbler::Digest) ? g : Gibbler::Digest.new(g)
120
120
  self.__gibbler_revert!
121
121
  }
122
122
  end
123
123
 
124
- self.__gibbler_cache
124
+ self.gibbler_cache
125
125
  end
126
126
 
127
127
  # Is the given digest +g+ contained in the history for this object?
@@ -150,7 +150,7 @@ class Hash
150
150
  include Gibbler::History
151
151
  def __gibbler_revert!
152
152
  self.clear
153
- self.merge! self.gibbler_object(self.__gibbler_cache)
153
+ self.merge! self.gibbler_object(self.gibbler_cache)
154
154
  end
155
155
  end
156
156
 
@@ -158,7 +158,7 @@ class Array
158
158
  include Gibbler::History
159
159
  def __gibbler_revert!
160
160
  self.clear
161
- self.push *(self.gibbler_object self.__gibbler_cache)
161
+ self.push *(self.gibbler_object self.gibbler_cache)
162
162
  end
163
163
  end
164
164
 
@@ -166,7 +166,7 @@ class String
166
166
  include Gibbler::History
167
167
  def __gibbler_revert!
168
168
  self.clear
169
- self << (self.gibbler_object self.__gibbler_cache)
169
+ self << (self.gibbler_object self.gibbler_cache)
170
170
  end
171
171
  end
172
172
 
@@ -6,7 +6,9 @@ module Gibbler
6
6
 
7
7
  def self.included(obj)
8
8
  obj.extend Attic
9
- obj.attic :__gibbler_cache
9
+ obj.attic :gibbler_cache
10
+ # Backwards compatibility for <= 0.6.2
11
+ obj.send :alias_method, :__gibbler_cache, :gibbler_cache
10
12
  end
11
13
 
12
14
  # Calculates a digest for the current object instance.
@@ -15,18 +17,20 @@ module Gibbler
15
17
  # on the digest type.
16
18
  def gibbler
17
19
  gibbler_debug :GIBBLER, self.class, self
18
- self.__gibbler_cache = Gibbler::Digest.new self.__gibbler
20
+ digest = Gibbler::Digest.new self.__gibbler
21
+ self.gibbler_cache = digest unless self.frozen?
22
+ digest
19
23
  end
20
24
 
21
25
  # Has this object been modified?
22
26
  #
23
27
  # This method compares the return value from digest with the
24
28
  # previous value returned by gibbler (the value is stored in
25
- # the attic as <tt>__gibbler_cache</tt>).
29
+ # the attic as <tt>gibbler_cache</tt>).
26
30
  # See Attic[http://github.com/delano/attic]
27
31
  def gibbled?
28
- self.__gibbler_cache ||= self.gibbler
29
- was, now = self.__gibbler_cache.clone, self.gibbler
32
+ self.gibbler_cache ||= self.gibbler
33
+ was, now = self.gibbler_cache.clone, self.gibbler
30
34
  gibbler_debug :gibbled?, was, now
31
35
  was != now
32
36
  end
data/lib/gibbler.rb CHANGED
@@ -13,7 +13,7 @@ module Gibbler
13
13
  #include Attic
14
14
  extend Attic
15
15
 
16
- VERSION = "0.6.2"
16
+ VERSION = "0.6.3"
17
17
 
18
18
  require 'gibbler/object'
19
19
  require 'gibbler/digest'
@@ -85,7 +85,7 @@ module Gibbler
85
85
 
86
86
  def self.included(obj)
87
87
  obj.extend Attic
88
- obj.attic :__gibbler_cache
88
+ obj.attic :gibbler_cache
89
89
  end
90
90
 
91
91
  # Creates a digest for the current state of self.
@@ -103,7 +103,7 @@ module Gibbler
103
103
  end
104
104
 
105
105
  def __gibbler_revert!
106
- state = self.gibbler_object self.__gibbler_cache
106
+ state = self.gibbler_object self.gibbler_cache
107
107
  state.instance_variables do |n|
108
108
  v = state.instance_variable_get n
109
109
  self.instance_variable_set v
@@ -132,7 +132,7 @@ module Gibbler
132
132
 
133
133
  def self.included(obj)
134
134
  obj.extend Attic
135
- obj.attic :__gibbler_cache
135
+ obj.attic :gibbler_cache
136
136
  end
137
137
 
138
138
  # Creates a digest for the current state of self.
@@ -167,7 +167,7 @@ module Gibbler
167
167
 
168
168
  def self.included(obj)
169
169
  obj.extend Attic
170
- obj.attic :__gibbler_cache
170
+ obj.attic :gibbler_cache
171
171
  end
172
172
 
173
173
  # Creates a digest for the current state of self.
@@ -207,7 +207,7 @@ module Gibbler
207
207
 
208
208
  def self.included(obj)
209
209
  obj.extend Attic
210
- obj.attic :__gibbler_cache
210
+ obj.attic :gibbler_cache
211
211
  end
212
212
 
213
213
  # Creates a digest for the current state of self.
@@ -246,7 +246,7 @@ module Gibbler
246
246
 
247
247
  def self.included(obj)
248
248
  obj.extend Attic
249
- obj.attic :__gibbler_cache
249
+ obj.attic :gibbler_cache
250
250
  end
251
251
 
252
252
  # Creates a digest for the current state of self.
@@ -277,7 +277,7 @@ module Gibbler
277
277
 
278
278
  def self.included(obj)
279
279
  obj.extend Attic
280
- obj.attic :__gibbler_cache
280
+ obj.attic :gibbler_cache
281
281
  end
282
282
 
283
283
  # Creates a digest for the current state of self.
@@ -308,7 +308,7 @@ module Gibbler
308
308
 
309
309
  def self.included(obj)
310
310
  obj.extend Attic
311
- obj.attic :__gibbler_cache
311
+ obj.attic :gibbler_cache
312
312
  end
313
313
 
314
314
  # Creates a digest for the current state of self.
@@ -341,7 +341,7 @@ module Gibbler
341
341
 
342
342
  def self.included(obj)
343
343
  obj.extend Attic
344
- obj.attic :__gibbler_cache
344
+ obj.attic :gibbler_cache
345
345
  end
346
346
 
347
347
  # Creates a digest for the current state of self.
@@ -367,7 +367,7 @@ module Gibbler
367
367
 
368
368
  def self.included(obj)
369
369
  obj.extend Attic
370
- obj.attic :__gibbler_cache
370
+ obj.attic :gibbler_cache
371
371
  end
372
372
 
373
373
  # Creates a digest for the current state of self.
@@ -402,7 +402,7 @@ module Gibbler
402
402
 
403
403
  def self.included(obj)
404
404
  obj.extend Attic
405
- obj.attic :__gibbler_cache
405
+ obj.attic :gibbler_cache
406
406
  end
407
407
 
408
408
  # Creates a digest for the current state of self.
@@ -18,9 +18,14 @@ tryouts "All methods" do
18
18
  Gibbler::Digest.new("1234567890").short
19
19
  end
20
20
 
21
- drill "can return true if compared with short", true do
21
+ drill "== is strict (only exact matches)", false do
22
22
  Gibbler::Digest.new("1234567890") == "12345678"
23
23
  end
24
+
25
+ drill "=== is relaxed (allows partial matches)", true do
26
+ Gibbler::Digest.new("1234567890") === "12345678"
27
+ end
28
+
24
29
 
25
30
  end
26
31
 
@@ -80,7 +80,7 @@ tryouts "Basic syntax with SHA1" do
80
80
  a, b = :something, :anything
81
81
  a.gibbler
82
82
  b.gibbler
83
- [a.__gibbler_cache.short, b.__gibbler_cache.short]
83
+ [a.gibbler_cache.short, b.gibbler_cache.short]
84
84
  end
85
85
 
86
86
  dream ["ce0c7694", "c13b2f02"]
@@ -88,18 +88,18 @@ tryouts "Basic syntax with SHA1" do
88
88
  a, b = 'something', 'anything'
89
89
  a.gibbler
90
90
  b.gibbler
91
- [a.__gibbler_cache.short, b.__gibbler_cache.short]
91
+ [a.gibbler_cache.short, b.gibbler_cache.short]
92
92
  end
93
93
 
94
- drill "Symbol has list of attic vars", [:__gibbler_cache] do
94
+ drill "Symbol has list of attic vars", [:gibbler_cache] do
95
95
  Symbol.attic_vars
96
96
  end
97
97
 
98
- drill "String has list of attic vars", [:__gibbler_cache] do
98
+ drill "String has list of attic vars", [:gibbler_cache] do
99
99
  String.attic_vars
100
100
  end
101
101
 
102
- drill "Hash has list of attic vars", [:__gibbler_cache] do
102
+ drill "Hash has list of attic vars", [:gibbler_cache] do
103
103
  Hash.attic_vars
104
104
  end
105
105
 
@@ -134,7 +134,7 @@ tryouts "Basic syntax with SHA1" do
134
134
  #stash :gstring_methods, Gibbler::String.methods.sort
135
135
  #stash :class_methods, a.class.methods.sort
136
136
  stash :ivars, a.instance_variables
137
- a.__gibbler_cache
137
+ a.gibbler_cache
138
138
  end
139
139
 
140
140
  end
@@ -16,7 +16,7 @@ tryouts "Speed", :benchmark do
16
16
  end
17
17
 
18
18
 
19
- dream :mean, 0.21
19
+ # dream :mean, 0.21
20
20
  drill "Array#gibbler", 5 do
21
21
  @@array.gibbler
22
22
  end
@@ -25,7 +25,7 @@ tryouts "Speed", :benchmark do
25
25
  @@hash.hash
26
26
  end
27
27
 
28
- dream :mean, 1.4
28
+ # dream :mean, 1.4
29
29
  drill "Hash#gibbler", 5 do
30
30
  @@hash.gibbler
31
31
  end
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.6.2
4
+ version: 0.6.3
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-09-15 00:00:00 -04:00
12
+ date: 2009-09-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency