Class: ReportFail
- Inherits:
-
Object
- Object
- ReportFail
- 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
-
#disabled_options ⇒ Object
readonly
Returns the value of attribute disabled_options.
-
#failed_labware_barcodes ⇒ Object
readonly
Returns the value of attribute failed_labware_barcodes.
-
#failure_id ⇒ Object
readonly
Returns the value of attribute failure_id.
-
#failure_options ⇒ Object
readonly
Returns the value of attribute failure_options.
-
#selected_option ⇒ Object
readonly
Returns the value of attribute selected_option.
-
#user_code ⇒ Object
readonly
Returns the value of attribute user_code.
Instance Method Summary collapse
- #failed_labware ⇒ Object
-
#initialize(user_code, failure_id, failed_labware_barcodes) ⇒ ReportFail
constructor
A new instance of ReportFail.
- #missing_barcodes ⇒ Object
- #persisted? ⇒ Boolean
-
#save ⇒ Object
save attempts to perform the actions, and returns true if it was successful This maintains compatibility with rails.
- #user ⇒ Object
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, ) @user_code = user_code.try(:strip) @failure_id = failure_id.try(:strip) @failed_labware_barcodes = ( || []).map(&:strip) end |
Instance Attribute Details
#disabled_options ⇒ Object (readonly)
Returns the value of attribute disabled_options.
11 12 13 |
# File 'app/models/report_fail.rb', line 11 def @disabled_options end |
#failed_labware_barcodes ⇒ Object (readonly)
Returns the value of attribute failed_labware_barcodes.
11 12 13 |
# File 'app/models/report_fail.rb', line 11 def @failed_labware_barcodes end |
#failure_id ⇒ Object (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_options ⇒ Object (readonly)
Returns the value of attribute failure_options.
11 12 13 |
# File 'app/models/report_fail.rb', line 11 def @failure_options end |
#selected_option ⇒ Object (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_code ⇒ Object (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_labware ⇒ Object
48 49 50 |
# File 'app/models/report_fail.rb', line 48 def failed_labware @failed_labware ||= Labware.() end |
#missing_barcodes ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/models/report_fail.rb', line 52 def = failed_labware.to_set(&:machine_barcode) = failed_labware.to_set(&:human_barcode) .delete_if do || .include?() || .include?() end end |
#persisted? ⇒ Boolean
27 28 29 |
# File 'app/models/report_fail.rb', line 27 def persisted? false end |
#save ⇒ Object
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.login) BroadcastEvent::LabwareFailed.create!(seed: labware, user: user, properties: { failure_reason: failure_id }) end valid? end |
#user ⇒ Object
31 32 33 |
# File 'app/models/report_fail.rb', line 31 def user @user ||= User.(@user_code) end |