From 0f691660485572b9822c30e3a648bd9cecc0cd4f Mon Sep 17 00:00:00 2001 From: "Justin S. Leitgeb" Date: Wed, 13 May 2009 14:34:09 -0400 Subject: [PATCH] Remove dependency on UUID in order to get key names that agree with AR object ID --- README.rdoc | 2 -- lib/hashpipe.rb | 9 +-------- lib/hashpipe/moneta_backend.rb | 2 +- spec/hashpipe_spec.rb | 2 +- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/README.rdoc b/README.rdoc index 0753f8d..5fbf3f7 100644 --- a/README.rdoc +++ b/README.rdoc @@ -36,8 +36,6 @@ Getting started with HashPipe is easy. config.gem "jsl-hashpipe", :lib => 'hashpipe', :source => 'http://gems.github.com' -* Add a column :uuid of type String, unique to the table where you want to use an hashpipe attribute (hattr) - * If you wanted to serialize an attribute 'elephant' in model Foo, you would call hattr :elephant in your model. For example, class 'Foo' may look like: diff --git a/lib/hashpipe.rb b/lib/hashpipe.rb index 13e6f32..8ae08ce 100644 --- a/lib/hashpipe.rb +++ b/lib/hashpipe.rb @@ -1,8 +1,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[hashpipe archived_attribute] )) require File.expand_path(File.join(File.dirname(__FILE__), %w[hashpipe global_configuration] )) -require 'uuid' - module HashPipe def self.included(base) @@ -20,8 +18,7 @@ def hattr(*args) if archived_attribute_definitions.nil? write_inheritable_attribute(:archived_attribute_definitions, {}) - before_save :generate_uuid - before_save :save_archived_attributes + after_save :save_archived_attributes before_destroy :destroy_archived_attributes end @@ -72,10 +69,6 @@ def destroy_archived_attributes end end - def generate_uuid - self.uuid = UUID.new.generate if self.new_record? - end - end end diff --git a/lib/hashpipe/moneta_backend.rb b/lib/hashpipe/moneta_backend.rb index 0b4f931..98291be 100644 --- a/lib/hashpipe/moneta_backend.rb +++ b/lib/hashpipe/moneta_backend.rb @@ -34,7 +34,7 @@ def require_moneta_library_for(cache_klass) def key_name [ table_name_from(@archived_attribute), @archived_attribute.name, - @archived_attribute.instance.uuid ].join('/') + @archived_attribute.instance.id ].join('/') end def table_name_from(archived_attribute) diff --git a/spec/hashpipe_spec.rb b/spec/hashpipe_spec.rb index 182220e..b885856 100644 --- a/spec/hashpipe_spec.rb +++ b/spec/hashpipe_spec.rb @@ -47,7 +47,7 @@ class Story < ActiveRecord::Base }.should_not change(@bear_story, :uuid) end - [:generate_uuid, :save_archived_attributes, :destroy_archived_attributes].each do |sym| + [:save_archived_attributes, :destroy_archived_attributes].each do |sym| it "should respond to attached storage method #{sym}" do Story.new.should respond_to(sym) end