Class: Quby::Answers::Repos::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/answers/repos/base.rb

Direct Known Subclasses

DiskRepo, MemoryRepo

Instance Method Summary collapse

Instance Method Details

#all(questionnaire_key) ⇒ Object



17
18
19
20
# File 'lib/quby/answers/repos/base.rb', line 17

def all(questionnaire_key)
  records = all_records(questionnaire_key)
  entities(records)
end

#create!(answer) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/quby/answers/repos/base.rb', line 22

def create!(answer)
  record = build_record
  record.questionnaire_key = answer.questionnaire_key
  update_attributes(record, answer)
  store_record(record)
  entity(record)
end

#find(questionnaire_key, answer_id, **options) ⇒ Object



7
8
9
10
11
# File 'lib/quby/answers/repos/base.rb', line 7

def find(questionnaire_key, answer_id, **options)
  record = find_record(answer_id)
  fail AnswerNotFound, "Answer #{answer_id.inspect} could not be found." unless record.present?
  entity(record)
end

#reload(answer) ⇒ Object



13
14
15
# File 'lib/quby/answers/repos/base.rb', line 13

def reload(answer)
  find(answer.questionnaire_key, answer.id)
end

#update!(answer) ⇒ Object



30
31
32
33
34
# File 'lib/quby/answers/repos/base.rb', line 30

def update!(answer)
  record = find_record(answer.id)
  update_attributes(record, answer)
  store_record(record)
end