Class: Quby::Answers::Services::UpdatesAnswers
- Inherits:
-
Object
- Object
- Quby::Answers::Services::UpdatesAnswers
- Defined in:
- lib/quby/answers/services/updates_answers.rb
Instance Attribute Summary collapse
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
Instance Method Summary collapse
-
#initialize(answer) ⇒ UpdatesAnswers
constructor
A new instance of UpdatesAnswers.
- #on_failure(&block) ⇒ Object
- #on_success(&block) ⇒ Object
- #update(new_attributes = {}) ⇒ Object
Constructor Details
#initialize(answer) ⇒ UpdatesAnswers
Returns a new instance of UpdatesAnswers.
12 13 14 |
# File 'lib/quby/answers/services/updates_answers.rb', line 12 def initialize(answer) @answer = answer end |
Instance Attribute Details
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
10 11 12 |
# File 'lib/quby/answers/services/updates_answers.rb', line 10 def answer @answer end |
Instance Method Details
#on_failure(&block) ⇒ Object
48 49 50 |
# File 'lib/quby/answers/services/updates_answers.rb', line 48 def on_failure(&block) @failure_callback = block end |
#on_success(&block) ⇒ Object
44 45 46 |
# File 'lib/quby/answers/services/updates_answers.rb', line 44 def on_success(&block) @success_callback = block end |
#update(new_attributes = {}) ⇒ Object
16 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 |
# File 'lib/quby/answers/services/updates_answers.rb', line 16 def update(new_attributes = {}) save_raw_params_on_error(new_attributes) do attribute_filter = FiltersAnswerValue.new(answer.questionnaire) attribute_filter.filter(new_attributes).each { |name, value| answer.send("#{name}=", value) } answer.extend AnswerValidations answer.cleanup_input answer.validate_answers if answer.errors.empty? if new_attributes["rendered_at"].present? started_at = Time.at(new_attributes["rendered_at"].to_i) else started_at = nil end answer.mark_completed(started_at) answer.outcome = OutcomeCalculation.new(answer).calculate Quby.answers.update!(answer) succeed! else if defined? ::Roqua::Support ::Roqua::Support::Errors.report(Quby::ValidationError.new(answer.errors.)) end fail! end end end |