Created
October 12, 2010 02:20
-
-
Save pedromg/621551 to your computer and use it in GitHub Desktop.
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
module DataMapper | |
module Model | |
# update_or_create method: finds and updates, or creates; | |
# merger is a boolean that determines if the conditions are merged with the attributes upon create; | |
# merge = true => merges conditions to attributes and passes the merge to the create method | |
# merge = false => only attributes are passed into the create method | |
def update_or_create(conditions = {}, attributes = {}, merger = true) | |
(first(conditions) && first(conditions).update(attributes)) || create(merger ? (conditions.merge(attributes)) : attributes ) | |
end | |
end # Module Model | |
end # Module DataMapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment