Permalink
Fetching contributors…
Cannot retrieve contributors at this time
131 lines (108 sloc) 3.14 KB
require 'gibbler/mixins'
#Gibbler.enable_debug
# include Gibbler raises exception
begin
a = Class.new
a.send :include, Gibbler
rescue TypeError
:success
end
#=> :success
# Symbol digests are consistent
:kimmy.gibbler
#=> '52be7494a602d85ff5d8a8ab4ffe7f1b171587df'
# String digests are consistent
'kimmy'.gibbler
#=> 'c8027100ecc54945ab15ddac529230e38b1ba6a1'
# String and Symbol return different digests
:kimmy.gibbler != "kimmy".gibbler
#=> true
# Class digests are consistent
Class.gibbler
#=> '25ac269ae3ef18cdb4143ad02ca315afb5026de9'
# Fixnum instance digests are consistent
1.gibbler
#=> 'a9cad665549bd22a4346fcf602d9d3c3b0482bbe'
# Bignum instance
100000000000.gibbler
#=> '608256db120251843843bba57e9b2c7adb7342aa'
# Empty Hash instance digests are consistent
Hash.new.gibbler
#=> '4fdcadc66a38feb9c57faf3c5a18d5e76a6d29bf'
# Populated Hash instance
{ :a => [1,2,3, [4,5,6]], :b => { :c => Class } }.gibbler
#=> "1d4b62e1e9f2c097b0cefb6877bf47c2015cdd21"
# Empty Array instance
Array.new.gibbler
#=> '48fda57c05684c9e5c3259557851943572183a21'
# Populated Array instance
[1, 2, :runtime, [3, "four", [Object, true]]].gibbler
#=> "3e1d79d113a409a96a13ca3879fc4c42027aa74b"
# Knows when a Hash has not changed
a = { :magic => true }
a.gibbler
a[:magic] = true
a.gibbled?
# => false
# Knows when a Hash has changed
a = { :magic => true }
a.gibbler
a[:magic] = false
a.gibbled?
#=> true
# Two Symbol digests don't cross streams
a, b = :something, :anything
a.gibbler
b.gibbler
[a.gibbler_cache.short, b.gibbler_cache.short]
#=> ["667ce086", "92d5f7cd"]
# Two String digests don't cross streams"
a, b = 'something', 'anything'
a.gibbler
b.gibbler
[a.gibbler_cache.short, b.gibbler_cache.short]
#=> ["ce0c7694", "c13b2f02"]
## DISABLED: If gibbler/history is required, there will be an
## additional attic_var (:gibbler_history), but only if the
## gibbler_history method has been called already (the history
## remains nil by default). The fix is not straightfroward and
## tests are not important anyway so disabling them is fine.
## Symbol has list of attic vars", [:gibbler_cache]
# Symbol.attic_vars
#end
#
## String has list of attic vars", [:gibbler_cache]
# String.attic_vars
#end
#
## Hash has list of attic vars", [:gibbler_cache]
# Hash.attic_vars
#end
# Freezing an object will update the digest
a = { :a => 1 }
pre = a.gibbler;
a[:a] = 2
post = a.freeze.gibbler
pre != post && post == a.gibbler_cache
#=> true
# works on arbitrary objects"
class ::FullHouse
include Gibbler::Complex
attr_accessor :roles
end
a = FullHouse.new
a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
a.gibbler
#=> "fa5f741275b6b27932537e1946042b0286286e1d"
# TODO: Update for Attic 0.4
# doesn't reveal @__gibbler_digest__ instance variable", false
a = {}
a.gibbler # We need to gibbler first so it sets a value to the instance var
val = RUBY_VERSION >= '1.9' ? :'@__gibbler_digest__' : '@__gibbler_digest__'
a.instance_variables.member? val
#=> false
# previous digest"
a = "kimmy"
a.gibbler
a.gibbler_cache
#=> 'c8027100ecc54945ab15ddac529230e38b1ba6a1'