gibbler 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt ADDED
@@ -0,0 +1,6 @@
1
+ GIBBLER, CHANGES
2
+
3
+
4
+ #### 0.2 (2009-06-25) ###############################
5
+
6
+ NOTE: Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Solutious Inc, Delano Mandelbaum
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = Gibbler - v0.2
2
+
3
+ Git-like hashes for Ruby objects.
4
+
5
+
6
+ config = {}
7
+ config.gibbler # => 57589e9811fe00c307ed3ab740cdac516c9975cb
8
+
9
+ config[:server] = {
10
+ :users => [:dave, :ali],
11
+ :ports => [22, 80, 443]
12
+ }
13
+ config.gibbler # => 87d792aefceb893b2d966828827c61636b0ace3e
14
+
15
+ config[:server][:users] << :yanni
16
+
17
+ config.gibbler # => 126ea10af73149ae4e69b0e036aa1d47a7651f07
18
+
19
+ == ALPHA NOTICE
20
+
21
+ This code is hella fresh. It's ugly and barely tested, but it's fun to play with. I'll happily accept patches.
22
+
23
+
24
+ == Credits
25
+
26
+ * Delano Mandelbaum (delano@solutious.com)
27
+
28
+
29
+ == License
30
+
31
+ See: LICENSE.txt
data/Rakefile ADDED
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require 'rake/clean'
3
+ require 'rake/gempackagetask'
4
+ require 'hanna/rdoctask'
5
+ require 'fileutils'
6
+ include FileUtils
7
+
8
+ task :default => :package
9
+
10
+ # CONFIG =============================================================
11
+
12
+ # Change the following according to your needs
13
+ README = "README.rdoc"
14
+ CHANGES = "CHANGES.txt"
15
+ LICENSE = "LICENSE.txt"
16
+
17
+ # Files and directories to be deleted when you run "rake clean"
18
+ CLEAN.include [ 'pkg', '*.gem', '.config']
19
+
20
+ name = 'gibbler'
21
+ load "#{name}.gemspec"
22
+ version = @spec.version
23
+
24
+ # That's it! The following defaults should allow you to get started
25
+ # on other things.
26
+
27
+
28
+ # TESTS/SPECS =========================================================
29
+
30
+
31
+
32
+ # INSTALL =============================================================
33
+
34
+ Rake::GemPackageTask.new(@spec) do |p|
35
+ p.need_tar = true if RUBY_PLATFORM !~ /mswin/
36
+ end
37
+
38
+ task :release => [ :rdoc, :package ]
39
+ task :install => [ :rdoc, :package ] do
40
+ sh %{sudo gem install pkg/#{name}-#{version}.gem}
41
+ end
42
+ task :uninstall => [ :clean ] do
43
+ sh %{sudo gem uninstall #{name}}
44
+ end
45
+
46
+
47
+ # RUBYFORGE RELEASE / PUBLISH TASKS ==================================
48
+
49
+ if @spec.rubyforge_project
50
+ desc 'Publish website to rubyforge'
51
+ task 'publish:rdoc' => 'doc/index.html' do
52
+ sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
53
+ end
54
+
55
+ desc 'Public release to rubyforge'
56
+ task 'publish:gem' => [:package] do |t|
57
+ sh <<-end
58
+ rubyforge add_release -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
59
+ rubyforge add_file -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
60
+ end
61
+ end
62
+ end
63
+
64
+
65
+
66
+ # RUBY DOCS TASK ==================================
67
+
68
+ Rake::RDocTask.new do |t|
69
+ t.rdoc_dir = 'doc'
70
+ t.title = @spec.summary
71
+ t.options << '--line-numbers'
72
+ t.options << '--charset' << 'utf-8'
73
+ t.rdoc_files.include(LICENSE)
74
+ t.rdoc_files.include(README)
75
+ t.rdoc_files.include(CHANGES)
76
+ t.rdoc_files.include('lib/**/*.rb')
77
+ end
78
+
79
+
data/gibbler.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ @spec = Gem::Specification.new do |s|
2
+ s.name = "gibbler"
3
+ s.rubyforge_project = "gibbler"
4
+ s.version = "0.2"
5
+ s.summary = "Gibbler: Git-like hashes for Ruby objects"
6
+ s.description = s.summary
7
+ s.author = "Delano Mandelbaum"
8
+ s.email = "delano@solutious.com"
9
+ s.homepage = "http://github.com/delano/gibbler"
10
+
11
+ # = EXECUTABLES =
12
+ # The list of executables in your project (if any). Don't include the path,
13
+ # just the base filename.
14
+ s.executables = %w[]
15
+
16
+ # Directories to extract rdocs from
17
+ s.require_paths = %w[lib]
18
+
19
+ # Specific files to include rdocs from
20
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
21
+ s.has_rdoc = true
22
+
23
+ # Update --main to reflect the default page to display
24
+ s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
25
+
26
+ # = MANIFEST =
27
+ s.files = %w(
28
+ README.rdoc
29
+ CHANGES.txt
30
+ LICENSE.txt
31
+ Rakefile
32
+ gibbler.gemspec
33
+ lib/gibbler.rb
34
+ )
35
+
36
+ s.has_rdoc = true
37
+ s.rubygems_version = '1.3.0'
38
+
39
+ end
data/lib/gibbler.rb ADDED
@@ -0,0 +1,82 @@
1
+
2
+ require 'digest/sha1'
3
+
4
+ # = Object
5
+ #
6
+ # "Hola, Tanneritos"
7
+ #
8
+ class Object
9
+
10
+ @@gibbler_digest_type = Digest::SHA1
11
+ @@gibbler_debug = false
12
+
13
+ # Specify a different digest class. The default is +Digest::SHA1+. You
14
+ # could try +Digest::SHA256+ by doing this:
15
+ #
16
+ # Object.gibbler_digest_type = Digest::SHA256
17
+ #
18
+ def self.gibbler_digest_type=(v)
19
+ @@gibbler_digest_type = v
20
+ 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)
24
+ def self.gibbler_debug?; @@gibbler_debug; end
25
+ # Enable debugging with a true value
26
+ def self.gibbler_debug=(v); @@gibbler_debug = v; end
27
+
28
+ # Calculates a digest for the current object instance.
29
+ # Objects that are a kind of Hash or Array are processed
30
+ # recursively. The length of the returned String depends
31
+ # on the digest type.
32
+ def to_gibble
33
+ gibbler_debug [:GIBBLER, self.class, self]
34
+ @__gibble__ = __default_gibbler self
35
+ end
36
+
37
+ # Has this object been modified?
38
+ def gibbled?
39
+ was, now = @__gibble__.clone, self.to_gibble
40
+ gibbler_debug [:gibbled?, was, now]
41
+ was != now
42
+ end
43
+
44
+ private
45
+ def __default_gibbler(h)
46
+ 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
+
75
+ end
76
+ end
77
+
78
+ def gibbler_debug(*args)
79
+ return unless @@gibbler_debug == true
80
+ p *args
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gibbler
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.2"
5
+ platform: ruby
6
+ authors:
7
+ - Delano Mandelbaum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-25 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "Gibbler: Git-like hashes for Ruby objects"
17
+ email: delano@solutious.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE.txt
25
+ files:
26
+ - README.rdoc
27
+ - CHANGES.txt
28
+ - LICENSE.txt
29
+ - Rakefile
30
+ - gibbler.gemspec
31
+ - lib/gibbler.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/delano/gibbler
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --line-numbers
39
+ - --title
40
+ - "Gibbler: Git-like hashes for Ruby objects"
41
+ - --main
42
+ - README.rdoc
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: gibbler
60
+ rubygems_version: 1.3.2
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: "Gibbler: Git-like hashes for Ruby objects"
64
+ test_files: []
65
+