Class: Batch::RequestFailAndRemover

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



8
9
10
# File 'app/models/batch/request_fail_and_remover.rb', line 8

def comment
  @comment
end

#reasonObject

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

#noticeObject



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

#saveObject



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.message.gsub(/\[[^\[]*\] /, ''))
  false
end