Created
July 27, 2011 17:14
-
-
Save DylanFM/1109883 to your computer and use it in GitHub Desktop.
Serialized values for indexed columns and drying up the serializing part a little too
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/bagman/bag.rb b/lib/bagman/bag.rb | |
index df32a92..cb6ee30 100644 | |
--- a/lib/bagman/bag.rb | |
+++ b/lib/bagman/bag.rb | |
@@ -51,17 +51,13 @@ module Bagman | |
end | |
target_class.send :define_method, "#{name}=" do |value| | |
+ serialised_value = self.class.serialise_value(value, options) | |
+ | |
if index_name = column.index_name | |
- write_attribute(index_name, value) | |
+ write_attribute(index_name, serialised_value) | |
end | |
- self.bag[name] = if s = options[:serialize] | |
- s[value] | |
- elsif value.is_a? Date | |
- value.to_s(:db) | |
- else | |
- value.to_s | |
- end | |
+ self.bag[name] = serialised_value | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment