Class: BenefitsIntake::SubmissionHandler::SavedClaim

Inherits:
Object
  • Object
show all
Defined in:
lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(saved_claim_id) ⇒ SavedClaim

constructor

Parameters:

  • saved_claim_id (Integer)

    the database id of the claim



10
11
12
13
14
15
16
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 10

def initialize(saved_claim_id)
  @claim = claim_class.find(saved_claim_id)
  @context = {
    form_id: claim.form_id,
    claim_id: claim.id
  }
end

Instance Attribute Details

#additional_contextObject (readonly, private)

Returns the value of attribute additional_context.



39
40
41
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 39

def additional_context
  @additional_context
end

#call_locationObject (readonly, private)

Returns the value of attribute call_location.



39
40
41
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 39

def call_location
  @call_location
end

#claimObject (readonly, private)

Returns the value of attribute claim.



39
40
41
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 39

def claim
  @claim
end

#contextObject (readonly, private)

Returns the value of attribute context.



39
40
41
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 39

def context
  @context
end

Instance Method Details

#claim_classObject (private)

the type of SavedClaim to be queried



42
43
44
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 42

def claim_class
  ::SavedClaim
end

#handle(result, call_location: nil, **additional_context) ⇒ Object

respond to result of a submission status

Parameters:

  • result (String)

    the resulting state of a submission

  • call_location (CallLocation) (defaults to: nil)

    where the result is being determined

  • **additional_context (Mixed)

    additional information to be logged



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 23

def handle(result, call_location: nil, **additional_context)
  @call_location = call_location
  @additional_context = context.merge(additional_context)

  case result
  when 'failure'
    on_failure
  when 'success'
    on_success
  when 'stale'
    on_stale
  end
end

#monitorObject (private)

the monitor to be used



48
49
50
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 48

def monitor
  @monitor ||= ZeroSilentFailures::Monitor.new('benefits-intake')
end

#notification_emailObject (private)

the email handler to be used



54
55
56
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 54

def notification_email
  nil
end

#on_failureObject (private)

handle a failure result



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 59

def on_failure
  avoided = false
  if notification_email
    notification_email.deliver(:error)
    avoided = true
  elsif claim.respond_to?('send_failure_email')
    claim.send_failure_email
    avoided = true
  end

  if avoided
    monitor.log_silent_failure_avoided(additional_context, nil, call_location:)
  else
    monitor.log_silent_failure(additional_context, nil, call_location:)
  end
rescue => e
  @additional_context = additional_context.merge({ message: e.message })
  monitor.log_silent_failure(additional_context, nil, call_location:)
  raise e
end

#on_staleObject (private)

handle a stale result



86
87
88
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 86

def on_stale
  true
end

#on_successObject (private)

handle a success result



81
82
83
# File 'lib/lighthouse/benefits_intake/submission_handler/saved_claim.rb', line 81

def on_success
  true
end