gibbler 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +10 -1
- data/README.rdoc +4 -3
- data/gibbler.gemspec +1 -1
- data/lib/gibbler.rb +63 -45
- metadata +2 -2
data/CHANGES.txt
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
GIBBLER, CHANGES
|
2
2
|
|
3
3
|
|
4
|
-
#### 0.
|
4
|
+
#### 0.3 (2009-06-29) #################################
|
5
|
+
|
6
|
+
* CHANGE: Renamed to_gibble -> gibble
|
7
|
+
* CHANGE: Renamed __default_gibbler to __gibbler
|
8
|
+
* CHANGE: Created Gibbler module, all other modules can
|
9
|
+
include its junk into their namespace.
|
10
|
+
* ADDED: Object#hash and performance tryouts
|
11
|
+
|
12
|
+
|
13
|
+
#### 0.2 (2009-06-25) #################################
|
5
14
|
|
6
15
|
NOTE: Initial release
|
data/README.rdoc
CHANGED
@@ -4,17 +4,18 @@ Git-like hashes for Ruby objects.
|
|
4
4
|
|
5
5
|
|
6
6
|
config = {}
|
7
|
-
config.
|
7
|
+
config.gibble # => 57589e9811fe00c307ed3ab740cdac516c9975cb
|
8
8
|
|
9
9
|
config[:server] = {
|
10
10
|
:users => [:dave, :ali],
|
11
11
|
:ports => [22, 80, 443]
|
12
12
|
}
|
13
|
-
config.
|
13
|
+
config.gibble # => 87d792aefceb893b2d966828827c61636b0ace3e
|
14
14
|
|
15
15
|
config[:server][:users] << :yanni
|
16
16
|
|
17
|
-
config.
|
17
|
+
config.gibble # => 126ea10af73149ae4e69b0e036aa1d47a7651f07
|
18
|
+
|
18
19
|
|
19
20
|
== ALPHA NOTICE
|
20
21
|
|
data/gibbler.gemspec
CHANGED
data/lib/gibbler.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
|
2
2
|
require 'digest/sha1'
|
3
3
|
|
4
|
-
# =
|
4
|
+
# = Gibbler
|
5
5
|
#
|
6
6
|
# "Hola, Tanneritos"
|
7
7
|
#
|
8
|
-
|
8
|
+
module Gibbler
|
9
|
+
VERSION = "0.3.0"
|
9
10
|
|
10
|
-
@@gibbler_digest_type = Digest::SHA1
|
11
11
|
@@gibbler_debug = false
|
12
|
+
@@gibbler_digest_type = Digest::SHA1
|
12
13
|
|
13
14
|
# Specify a different digest class. The default is +Digest::SHA1+. You
|
14
15
|
# could try +Digest::SHA256+ by doing this:
|
@@ -18,65 +19,82 @@ class Object
|
|
18
19
|
def self.gibbler_digest_type=(v)
|
19
20
|
@@gibbler_digest_type = v
|
20
21
|
end
|
21
|
-
|
22
|
-
def self.gibbler_digest_type; @@gibbler_digest_type; end
|
23
|
-
# Returns the current debug status (true or false)
|
22
|
+
# Returns the current debug status (true or false)
|
24
23
|
def self.gibbler_debug?; @@gibbler_debug; end
|
25
|
-
|
24
|
+
# Enable debugging with a true value
|
26
25
|
def self.gibbler_debug=(v); @@gibbler_debug = v; end
|
27
|
-
|
26
|
+
# Returns the current digest class.
|
27
|
+
def self.gibbler_digest_type; @@gibbler_digest_type; end
|
28
|
+
|
28
29
|
# Calculates a digest for the current object instance.
|
29
30
|
# Objects that are a kind of Hash or Array are processed
|
30
31
|
# recursively. The length of the returned String depends
|
31
32
|
# on the digest type.
|
32
|
-
def
|
33
|
+
def gibble
|
34
|
+
#if h.respond_to? :__custom_gibbler
|
35
|
+
# d = h.__custom_gibbler
|
36
|
+
# a = __gibbler '%s:%s:%s' % [klass, d.size, d]
|
37
|
+
# gibbler_debug [klass, a]
|
38
|
+
# a
|
39
|
+
#end
|
33
40
|
gibbler_debug [:GIBBLER, self.class, self]
|
34
|
-
@__gibble__ =
|
41
|
+
@__gibble__ = self.__gibbler
|
35
42
|
end
|
36
43
|
|
37
44
|
# Has this object been modified?
|
38
45
|
def gibbled?
|
39
|
-
was, now = @__gibble__.clone, self.
|
46
|
+
was, now = @__gibble__.clone, self.gibble
|
40
47
|
gibbler_debug [:gibbled?, was, now]
|
41
48
|
was != now
|
42
49
|
end
|
43
50
|
|
44
|
-
|
45
|
-
|
51
|
+
def gibbler_debug(*args)
|
52
|
+
return unless @@gibbler_debug == true
|
53
|
+
p *args
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Hash
|
58
|
+
include Gibbler
|
59
|
+
|
60
|
+
def __gibbler(h=self)
|
46
61
|
klass = h.class
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
a
|
68
|
-
|
69
|
-
else
|
70
|
-
value = h.nil? ? "\0" : h.to_s
|
71
|
-
a=@@gibbler_digest_type.hexdigest "%s:%d:%s" % [klass, value.size, value]
|
72
|
-
gibbler_debug [klass, value.size, value, a]
|
73
|
-
a
|
74
|
-
|
62
|
+
d = h.keys.sort { |a,b| a.inspect <=> b.inspect }
|
63
|
+
d.collect! do |name|
|
64
|
+
'%s:%s:%s' % [klass, name, h[name].__gibbler]
|
65
|
+
end
|
66
|
+
a = d.join($/).__gibbler
|
67
|
+
gibbler_debug [klass, a]
|
68
|
+
a
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class Array
|
74
|
+
extend Gibbler
|
75
|
+
|
76
|
+
def __gibbler(h=self)
|
77
|
+
klass = h.class
|
78
|
+
d, index = [], 0
|
79
|
+
h.each do |value|
|
80
|
+
d << '%s:%s:%s' % [h.class, index, value.__gibbler]
|
81
|
+
index += 1
|
75
82
|
end
|
83
|
+
a = d.join($/).__gibbler
|
84
|
+
gibbler_debug [klass, a]
|
85
|
+
a
|
76
86
|
end
|
77
87
|
|
78
|
-
|
79
|
-
|
80
|
-
|
88
|
+
end
|
89
|
+
|
90
|
+
class Object
|
91
|
+
include Gibbler
|
92
|
+
|
93
|
+
def __gibbler(h=self)
|
94
|
+
klass = h.class
|
95
|
+
value = h.nil? ? "\0" : h.to_s
|
96
|
+
a=@@gibbler_digest_type.hexdigest "%s:%d:%s" % [klass, value.size, value]
|
97
|
+
gibbler_debug [klass, value.size, value, a]
|
98
|
+
a
|
81
99
|
end
|
82
|
-
end
|
100
|
+
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.
|
4
|
+
version: "0.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-06-
|
12
|
+
date: 2009-06-29 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|