Skip to content

Instantly share code, notes, and snippets.

@dungdm93
Created March 16, 2016 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dungdm93/5dc1ecc8a2ea34c0e1cc to your computer and use it in GitHub Desktop.
Save dungdm93/5dc1ecc8a2ea34c0e1cc to your computer and use it in GitHub Desktop.
serialize using YAML coder
###
# define serialize in +ActiveRecord::AttributeMethods::Serialization#serialization+
# => create coder
# which is used in +ActiveRecord::Type::Serialized+
# attr is loaded in +ActiveRecord::Type::Serialized#type_cast_from_database+
# attr is dumped in +ActiveRecord::Type::Serialized#type_cast_for_database+
###
# active_record/coders/yaml.rb
module ActiveRecord::Coders
class YAML
def self.dump(obj)
::YAML.dump obj
end
def self.load(yaml)
::YAML.load yaml unless yaml.nil?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment