Created
March 16, 2016 09:24
-
-
Save dungdm93/5dc1ecc8a2ea34c0e1cc to your computer and use it in GitHub Desktop.
serialize using YAML coder
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
### | |
# 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