gibbler 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGES.txt +10 -1
  2. data/README.rdoc +4 -3
  3. data/gibbler.gemspec +1 -1
  4. data/lib/gibbler.rb +63 -45
  5. metadata +2 -2
data/CHANGES.txt CHANGED
@@ -1,6 +1,15 @@
1
1
  GIBBLER, CHANGES
2
2
 
3
3
 
4
- #### 0.2 (2009-06-25) ###############################
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.gibbler # => 57589e9811fe00c307ed3ab740cdac516c9975cb
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.gibbler # => 87d792aefceb893b2d966828827c61636b0ace3e
13
+ config.gibble # => 87d792aefceb893b2d966828827c61636b0ace3e
14
14
 
15
15
  config[:server][:users] << :yanni
16
16
 
17
- config.gibbler # => 126ea10af73149ae4e69b0e036aa1d47a7651f07
17
+ config.gibble # => 126ea10af73149ae4e69b0e036aa1d47a7651f07
18
+
18
19
 
19
20
  == ALPHA NOTICE
20
21
 
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.2"
4
+ s.version = "0.3"
5
5
  s.summary = "Gibbler: Git-like hashes for Ruby objects"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
data/lib/gibbler.rb CHANGED
@@ -1,14 +1,15 @@
1
1
 
2
2
  require 'digest/sha1'
3
3
 
4
- # = Object
4
+ # = Gibbler
5
5
  #
6
6
  # "Hola, Tanneritos"
7
7
  #
8
- class Object
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
- # Returns the current digest class.
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
- # Enable debugging with a true value
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 to_gibble
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__ = __default_gibbler self
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.to_gibble
46
+ was, now = @__gibble__.clone, self.gibble
40
47
  gibbler_debug [:gibbled?, was, now]
41
48
  was != now
42
49
  end
43
50
 
44
- private
45
- def __default_gibbler(h)
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
- if h.respond_to? :__custom_gibbler
48
- h.__custom_gibbler
49
-
50
- elsif h.kind_of?(Hash) || h.respond_to?(:keys)
51
- d = h.keys.sort { |a,b| a.inspect <=> b.inspect }
52
- d.collect! do |name|
53
- '%s:%s:%s' % [klass, name, __default_gibbler(h[name])]
54
- end
55
- a = __default_gibbler d.join($/)
56
- gibbler_debug [klass, a]
57
- a
58
-
59
- elsif h.kind_of?(Array)
60
- d, index = [], 0
61
- h.each do |value|
62
- d << '%s:%s:%s' % [h.class, index, __default_gibbler(value)]
63
- index += 1
64
- end
65
- a = __default_gibbler d.join($/)
66
- gibbler_debug [klass, a]
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
- def gibbler_debug(*args)
79
- return unless @@gibbler_debug == true
80
- p *args
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.2"
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-25 00:00:00 -04:00
12
+ date: 2009-06-29 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15