Permalink
Browse files

fully functional --> modified to has_serialized

Signed-off-by: acuppy <acuppy@gmail.com>
  • Loading branch information...
1 parent 5b41c44 commit 1f4fe5bf74952c37adf60f744f20dd81102f0bf2 @acuppy acuppy committed Apr 3, 2011
Showing with 9 additions and 13 deletions.
  1. +3 −3 README
  2. +1 −3 init.rb
  3. +5 −7 lib/{attribute_serializer.rb → active_record/has_serialized_association.rb}
View
6 README
@@ -9,7 +9,7 @@ Example
=======
class User < ActiveRecord::Base
- serializable :preferences, :show_email => false, :locale => :en
+ has_serialized :preferences, :show_email => false, :locale => :en
end
u = User.new # automatically assigns the default preferences
@@ -18,7 +18,7 @@ u.preferences
u.show_email = true # I can change it like an attribute via @user.update_attributes(params[:user])
u.preferences
-=> {:show_email => true, :locale => :en}
+=> {:show_email => true, :locale => :en }
-Copyright (c) 2011 Greg Moreno, released under the MIT license
+Copyright (c) 2011 Greg Moreno and Adam Cuppy, released under the MIT license
View
@@ -1,3 +1 @@
-require 'attribute_serializer'
-
-ActiveRecord::Base.send :include, ActiveRecord::AttributeSerializer
+ActiveRecord::Base.send :include, ActiveRecord::HasSerializedAssociation
@@ -2,20 +2,19 @@
# http://gregmoreno.ca/preventing-model-explosion-via-rails-serialization/
module ActiveRecord
- module AttributeSerializer
-
- def included(base)
+ module HasSerializedAssociation
+ def self.included(base)
base.send :extend, ClassMethods
- Rails.logger.debug "---- AttributeSerializer loaded ----"
+ Rails.logger.debug "---- HasSerialized loaded ----"
end
module ClassMethods
- def serializeable(serialized, serialized_accessors={})
+ def has_serialized(serialized, serialized_accessors={})
serialize serialized, serialized_accessors.class
serialized_attr_accessor serialized, serialized_accessors
- default_serialized_attr serialized, serialized_accessors
+ default_serialized_attr serialized, serialized_accessors
end
# Creates the accessors
@@ -41,6 +40,5 @@ def default_serialized_attr(serialized, accessors)
end
end
end
-
end
end

0 comments on commit 1f4fe5b

Please sign in to comment.