Class: ReportFail

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/report_fail.rb

Overview

A class to action on failed labware events

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_code, failure_id, failed_labware_barcodes) ⇒ ReportFail

Returns a new instance of ReportFail.



21
22
23
24
25
# File 'app/models/report_fail.rb', line 21

def initialize(user_code, failure_id, failed_labware_barcodes)
  @user_code = user_code.try(:strip)
  @failure_id = failure_id.try(:strip)
  @failed_labware_barcodes = (failed_labware_barcodes || []).map(&:strip)
end

Instance Attribute Details

#disabled_optionsObject (readonly)

Returns the value of attribute disabled_options.



11
12
13
# File 'app/models/report_fail.rb', line 11

def disabled_options
  @disabled_options
end

#failed_labware_barcodesObject (readonly)

Returns the value of attribute failed_labware_barcodes.



11
12
13
# File 'app/models/report_fail.rb', line 11

def failed_labware_barcodes
  @failed_labware_barcodes
end

#failure_idObject (readonly)

Returns the value of attribute failure_id.



11
12
13
# File 'app/models/report_fail.rb', line 11

def failure_id
  @failure_id
end

#failure_optionsObject (readonly)

Returns the value of attribute failure_options.



11
12
13
# File 'app/models/report_fail.rb', line 11

def failure_options
  @failure_options
end

#selected_optionObject (readonly)

Returns the value of attribute selected_option.



11
12
13
# File 'app/models/report_fail.rb', line 11

def selected_option
  @selected_option
end

#user_codeObject (readonly)

Returns the value of attribute user_code.



11
12
13
# File 'app/models/report_fail.rb', line 11

def user_code
  @user_code
end

Instance Method Details

#failed_labwareObject



48
49
50
# File 'app/models/report_fail.rb', line 48

def failed_labware
  @failed_labware ||= Labware.with_barcode(failed_labware_barcodes)
end

#missing_barcodesObject



52
53
54
55
56
57
58
# File 'app/models/report_fail.rb', line 52

def missing_barcodes
  machine_barcodes = failed_labware.to_set(&:machine_barcode)
  human_barcodes = failed_labware.to_set(&:human_barcode)
  failed_labware_barcodes.delete_if do |barcode|
    human_barcodes.include?(barcode) || machine_barcodes.include?(barcode)
  end
end

#persisted?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/report_fail.rb', line 27

def persisted?
  false
end

#saveObject

save attempts to perform the actions, and returns true if it was successful This maintains compatibility with rails



37
38
39
40
41
42
43
44
45
46
# File 'app/models/report_fail.rb', line 37

def save
  return false unless valid?

  failed_labware.each do |labware|
    labware.events.create_labware_failed!(failure_id, user.)
    BroadcastEvent::LabwareFailed.create!(seed: labware, user: user, properties: { failure_reason: failure_id })
  end

  valid?
end

#userObject



31
32
33
# File 'app/models/report_fail.rb', line 31

def user
  @user ||= User.find_with_barcode_or_swipecard_code(@user_code)
end