Class: Form526SubmissionRemediation

Inherits:
ApplicationRecord show all
Defined in:
app/models/form526_submission_remediation.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'form526_submission_remediation'

Instance Method Summary collapse

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Instance Method Details

#add_context_to_lifecycle(context) ⇒ Object (private)



42
43
44
45
46
47
48
49
50
# File 'app/models/form526_submission_remediation.rb', line 42

def add_context_to_lifecycle(context)
  if context.is_a?(String) && context.strip.present?
    self.lifecycle << "#{Time.current.strftime('%Y-%m-%d %H:%M:%S')} -- #{context}"
    true
  else
    errors.add(:base, 'Context must be a non-empty string')
    false
  end
end

#ensure_success_if_ignored_as_duplicateObject (private)



34
35
36
# File 'app/models/form526_submission_remediation.rb', line 34

def ensure_success_if_ignored_as_duplicate
  errors.add(:success, 'must be true if ignored as duplicate') if ignored_as_duplicate? && !success
end

#initialize_lifecycleObject (private)



26
27
28
# File 'app/models/form526_submission_remediation.rb', line 26

def initialize_lifecycle
  self.lifecycle ||= []
end

#log_to_datadog(context) ⇒ Object (private)



38
39
40
# File 'app/models/form526_submission_remediation.rb', line 38

def log_to_datadog(context)
  StatsD.increment("#{STATSD_KEY_PREFIX} marked as unsuccessful: #{context}")
end

#mark_as_unsuccessful(context) ⇒ Object



16
17
18
19
20
21
22
# File 'app/models/form526_submission_remediation.rb', line 16

def mark_as_unsuccessful(context)
  self.success = false
  if add_context_to_lifecycle(context)
    save!
    log_to_datadog(context)
  end
end

#new_or_changed?Boolean (private)

Returns:

  • (Boolean)


52
53
54
# File 'app/models/form526_submission_remediation.rb', line 52

def new_or_changed?
  new_record? || changed?
end

#validate_context_on_create_updateObject (private)



30
31
32
# File 'app/models/form526_submission_remediation.rb', line 30

def validate_context_on_create_update
  errors.add(:base, 'Context required for create/update actions') if lifecycle.empty? || lifecycle.last.blank?
end