Class: Batch::RequestFailAndRemover
- Inherits:
-
Object
- Object
- Batch::RequestFailAndRemover
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/batch/request_fail_and_remover.rb
Overview
Handles failure of requests or their removal from the batch via BatchesController#fail_items
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#reason ⇒ Object
Returns the value of attribute reason.
Instance Method Summary collapse
- #failure=(failure_hash) ⇒ Object
-
#id=(batch_id) ⇒ Object
ID is the batch id passed in from the controller.
- #notice ⇒ Object
-
#requested_fail=(selected_fields) ⇒ Object
This input comes in via the controller.
-
#requested_remove=(selected_fields) ⇒ Object
This input comes in via the controller.
- #save ⇒ Object
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
8 9 10 |
# File 'app/models/batch/request_fail_and_remover.rb', line 8 def comment @comment end |
#reason ⇒ Object
Returns the value of attribute reason.
8 9 10 |
# File 'app/models/batch/request_fail_and_remover.rb', line 8 def reason @reason end |
Instance Method Details
#failure=(failure_hash) ⇒ Object
42 43 44 45 46 |
# File 'app/models/batch/request_fail_and_remover.rb', line 42 def failure=(failure_hash) @reason = failure_hash[:reason] @comment = failure_hash[:comment] @fail_but_charge = failure_hash[:fail_but_charge] end |
#id=(batch_id) ⇒ Object
ID is the batch id passed in from the controller
49 50 51 |
# File 'app/models/batch/request_fail_and_remover.rb', line 49 def id=(batch_id) @batch = Batch.find(batch_id) end |
#notice ⇒ Object
38 39 40 |
# File 'app/models/batch/request_fail_and_remover.rb', line 38 def notice @notice ||= [] end |
#requested_fail=(selected_fields) ⇒ Object
This input comes in via the controller. It represents a series of checkboxes which each have the value ‘on’ when checked. We filter out ‘control’ which is used in place of the request id for some older batches. We convert it to an array of the request_ids we care about
57 58 59 |
# File 'app/models/batch/request_fail_and_remover.rb', line 57 def requested_fail=(selected_fields) @requested_fail = selected_fields.except('control').select { |_k, v| v == 'on' }.keys end |
#requested_remove=(selected_fields) ⇒ Object
This input comes in via the controller. It represents a series of checkboxes which each have the value ‘on’ when checked. We filter out ‘control’ which is used in place of the request id for some older batches. We convert it to an array of the request_ids we care about
65 66 67 |
# File 'app/models/batch/request_fail_and_remover.rb', line 65 def requested_remove=(selected_fields) @requested_remove = selected_fields.except('control').select { |_k, v| v == 'on' }.keys end |
#save ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/batch/request_fail_and_remover.rb', line 23 def save return false unless valid? ActiveRecord::Base.transaction do fail_requests if requested_fail.present? remove_requests if requested_remove.present? end true rescue ActiveRecord::RecordNotFound => e # Make the returned error a little more user friendly by stripping out the SQL errors.add(:base, e..gsub(/\[[^\[]*\] /, '')) false end |