Last active
August 29, 2015 13:57
-
-
Save alyssais/9436408 to your computer and use it in GitHub Desktop.
Make motion-yaml retain original YAML if object being re-serialized has not been modified.
This file contains hidden or 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
class << YAML | |
alias _load load | |
private :_load | |
def load(yaml) | |
hash = _load(yaml) | |
unless hash.nil? | |
hash.instance_variable_set(:@original_yaml, yaml) | |
hash.instance_variable_set(:@original_parsed_yaml, hash) | |
end | |
hash | |
end | |
alias _dump dump | |
private :_dump | |
def dump(object) | |
unless object.nil? | |
object.instance_eval do | |
if @original_parsed_yaml == self | |
@original_yaml | |
else | |
YAML.send(:_dump, self) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment