Last active
December 14, 2015 01:39
-
-
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.
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
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