Module: Mongo::Voteable::Voting::ClassMethods
- Defined in:
- lib/voteable_mongo/voting.rb
Instance Method Summary collapse
-
#vote(options) ⇒ votee, false
Make a vote on an object of this class.
Instance Method Details
#vote(options) ⇒ votee, false
Make a vote on an object of this class
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/voteable_mongo/voting.rb', line 17 def vote() () [:voteable] = VOTEABLE[name][name] if [:voteable] query, update = if [:revote] revote_query_and_update() elsif [:unvote] unvote_query_and_update() else new_vote_query_and_update() end # http://www.mongodb.org/display/DOCS/findAndModify+Command begin doc = where(query).find_and_modify( update, :new => true ) rescue Moped::Errors::OperationFailure doc = nil end if doc update_parent_votes(doc, ) if [:voteable][:update_parents] # Update new votes data [:votee].write_attribute('votes', doc['votes']) if [:votee] [:votee] || new(doc.as_document) else false end end end |