Class: Quby::Answers::Repos::MongoidRepo

Inherits:
Base
  • Object
show all
Defined in:
lib/quby/answer_repos/mongoid_repo.rb

Defined Under Namespace

Classes: Record

Instance Method Summary collapse

Instance Method Details

#find_completed_after(time, answer_ids) ⇒ Object



47
48
49
50
# File 'lib/quby/answer_repos/mongoid_repo.rb', line 47

def find_completed_after(time, answer_ids)
  records = Record.any_in(_id: answer_ids).where(:completed_at.gt => time)
  records.map { |record| entity(record) }
end

#update!(answer) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/quby/answer_repos/mongoid_repo.rb', line 52

def update!(answer)
  record = find_record(answer.id)
  # MongoDB won't save new hash order if we don't clear it first.
  record.update_attributes!(scores: {}, actions: {}, completion: {})
  update_attributes(record, answer)
  store_record(record)
end