Skip to content

Instantly share code, notes, and snippets.

@alyssais
Last active August 29, 2015 13:57
Show Gist options
  • Save alyssais/9436408 to your computer and use it in GitHub Desktop.
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.
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