From 22ec830da2fa963c4813697d0fb6e67ec69991e5 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Mon, 19 Nov 2012 16:41:33 -0500 Subject: [PATCH] Added hash key example. --- examples/hash_key.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/hash_key.rb diff --git a/examples/hash_key.rb b/examples/hash_key.rb new file mode 100644 index 0000000..f506c8c --- /dev/null +++ b/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=> + +pp track.bucket # => "2012" +pp track.track_id # => + +track.bucket = '2011' + +pp track.id # => :bucket is now "2011" +pp track.id_changed? # => true