Skip to content

Instantly share code, notes, and snippets.

@DylanFM
Created July 27, 2011 17:14
Show Gist options
  • Save DylanFM/1109883 to your computer and use it in GitHub Desktop.
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
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