Skip to content

Instantly share code, notes, and snippets.

@vivien
Last active December 14, 2015 01:39
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 vivien/5008035 to your computer and use it in GitHub Desktop.
Save vivien/5008035 to your computer and use it in GitHub Desktop.
Module to mixin into a DataMapper model to add a #to_hash method returning a hash with loaded properties.
module ToHash
def to_loaded_hash
fields = properties.select { |p| p.loaded?(self) }.map(&:name)
hash = {}
fields.each { |f| hash[f] = self[f] }
hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment