gibbler / 0.5.0
| Short description: | Git-like hashes for Ruby objects | |||||
|---|---|---|---|---|---|---|
| Category: | Library/Development | |||||
| Status: | alpha | |||||
| Created: | 2009-07-01 00:57:34 GMT | |||||
| Last update: | 2009-07-02 00:20:11 GMT | |||||
| Owner: | delano (Projects of this owner) | |||||
| Homepage: | http://github.com/delano/gibbler | |||||
| Download: | http://github.com/delano/gibbler/tarball/latest | |||||
| License: | BSD-type | |||||
| Dependency: |
|
|||||
| Description: | Gibbler - v0.5 ALPHAGit-like hashes and history for Ruby objects. Example 1 — Basic Usage
require 'gibbler'
config = {}
config.gibbler # => 4fdcadc66a38feb9c57faf3c5a18d5e76a6d29bf
config.gibbled? # => false
config[:server] = {
:users => [:dave, :ali],
:ports => [22, 80, 443]
}
config.gibbled? # => true
config.gibbler # => ef23d605f8c4fc80a8e580f9a0e8dab8426454a8
config[:server][:users] << :yanni
config.gibbler # => 4c558a56bc2abf5f8a845a69e47ceb5e0003683f
config.gibbler.short # => 4c558a56
Example 2 — Object HistoryGibbler can also keep track of the history of changes to an object. By default Gibbler supports history for Hash, Array, and String objects. The gibbler_commit method creates a clone of the current object and stores in an instance variable using the current hash digest as the key.
require 'gibbler'
require 'gibbler/history'
a = { :magic => :original }
a.gibbler_commit # => d7049916ddb25e6cc438b1028fb957e5139f9910
a[:magic] = :updated
a.gibbler_commit # => b668098e16d08898532bf3aa33ce2253a3a4150e
a[:magic] = :changed
a.gibbler_commit # => 0b11c377fccd44554a601e5d2b135c46dc1c4cb1
a.gibbler_history # => d7049916, b668098e, 0b11c377
a.gibbler_revert 'd7049916' # Return to a specific commit
a.gibbler # => d7049916ddb25e6cc438b1028fb957e5139f9910
a # => { :magic => :original }
a.delete :magic
a.gibbler_revert # Return to the previous commit
a.gibbler # => 0b11c377fccd44554a601e5d2b135c46dc1c4cb1
a # => { :magic => :changed }
a.gibbler_object 'b668098e' # => { :magic => :updated }
a.gibbler_stamp # => 2009-07-01 18:56:52 -0400
Supported ClassesGibbler methods are available only to the classes which explicitly include them (see RDocs for details on which classes are supported by default). You can also extend custom objects:
class FullHouse
include Gibbler::Complex
attr_accessor :roles
end
a = FullHouse.new
a.gibbler # => 4192d4cb59975813f117a51dcd4454ac16df6703
a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
a.gibbler # => 6ea546919dc4caa2bab69799b71d48810a1b48fa
Gibbler::Complex creates a digest based on the name of the class and the names and values of the instance variables. See the RDocs for other Gibbler::* types. If you want to support all Ruby objects, add the following to your application:
class Object
include Gibbler::String
end
Gibbler::String creates a digest based on the name of the class and the output of the to_s method. This is a reasonable default for most objects however any object that includes the object address in to_s (e.g. "<Object:0x0x4ac9f0…") will produce unreliable digests (because the address can change). ALPHA NoticeThis code is hella fresh (est 2009-06-25). It’s barely tested and the interface may change, but it’s fun to play with. I’ll happily accept patches. NOTE: Gibbler history is not suitable for very large objects since it keeps complete copies of the object in memory. This is a very early implementation of this feature so don’t rely on it for production code. News2009-07-01: Major namespace reorganizationMany method names have been modified so this release is not backwards compatible with previous releases. This clears up ambiguity regarding "gibbles". They’re now rightly referred to as digests. 2009-06-30: Digests have changed in 0.4Digests have changed between 0.3 and 0.4. Ones created with 0.3 and earlier will not match ones created with 0.4 for the same object. Known Issues
More InfoCredits
LicenseSee: LICENSE.txt |
|||||
| Versions: | [0.7.1 (2009-10-16)] [0.6.0 (2009-07-20)] [0.5.3 (2009-07-13)] [0.5.2 (2009-07-08)] [0.5.0 (2009-07-02)] [0.4.0 (2009-07-01)] | |||||