Skip to content

Commit

Permalink
Added hash key example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Nov 19, 2012
1 parent 1474964 commit 22ec830
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/hash_key.rb
@@ -0,0 +1,33 @@
require 'pp'
require 'rubygems'
require 'pathname'

root_path = Pathname(__FILE__).dirname.join('..').expand_path
lib_path = root_path.join('lib')
$:.unshift(lib_path)

require 'toystore'

class Track
include Toy::Store

adapter :memory, {}

key :hash, attributes: {
bucket: String,
track_id: SimpleUUID::UUID,
}
end

track = Track.new(:bucket => '2012')

pp track.id
# => {:bucket=>"2012", :track_id=> <UUID#70194110090200 time: 2012-11-19 16:40:24 -0500, usecs: 149874 jitter: 11675517131681036675>

pp track.bucket # => "2012"
pp track.track_id # => <UUID#70194110090200 time: 2012-11-19 16:40:24 -0500, usecs: 149874 jitter: 11675517131681036675>

track.bucket = '2011'

pp track.id # => :bucket is now "2011"
pp track.id_changed? # => true

0 comments on commit 22ec830

Please sign in to comment.