Class: LabwhereReception
- Inherits:
-
Object
- Object
- LabwhereReception
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/labwhere_reception.rb
Overview
A simple class to handle the behaviour from the labwhere reception controller
Instance Attribute Summary collapse
-
#asset_barcodes ⇒ Object
readonly
Returns the value of attribute asset_barcodes.
-
#location_barcode ⇒ Object
readonly
Returns the value of attribute location_barcode.
-
#user_code ⇒ Object
Returns the value of attribute user_code.
Instance Method Summary collapse
-
#assets ⇒ Object
rubocop:enable Metrics/MethodLength.
- #id ⇒ Object
-
#initialize(user_code, location_barcode, asset_barcodes) ⇒ LabwhereReception
constructor
A new instance of LabwhereReception.
- #missing_barcodes ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
-
#save ⇒ Object
save attempts to perform the actions, and returns true if it was successful This maintains compatibility with rails rubocop:todo Metrics/MethodLength.
- #user ⇒ Object
Constructor Details
#initialize(user_code, location_barcode, asset_barcodes) ⇒ LabwhereReception
Returns a new instance of LabwhereReception.
22 23 24 25 26 |
# File 'app/models/labwhere_reception.rb', line 22 def initialize(user_code, , ) @asset_barcodes = ( || []).map(&:strip) @location_barcode = .try(:strip) @user_code = user_code.try(:strip) end |
Instance Attribute Details
#asset_barcodes ⇒ Object (readonly)
Returns the value of attribute asset_barcodes.
12 13 14 |
# File 'app/models/labwhere_reception.rb', line 12 def @asset_barcodes end |
#location_barcode ⇒ Object (readonly)
Returns the value of attribute location_barcode.
12 13 14 |
# File 'app/models/labwhere_reception.rb', line 12 def @location_barcode end |
#user_code ⇒ Object
Returns the value of attribute user_code.
11 12 13 |
# File 'app/models/labwhere_reception.rb', line 11 def user_code @user_code end |
Instance Method Details
#assets ⇒ Object
rubocop:enable Metrics/MethodLength
88 89 90 |
# File 'app/models/labwhere_reception.rb', line 88 def assets @assets ||= Labware.() end |
#id ⇒ Object
28 29 30 |
# File 'app/models/labwhere_reception.rb', line 28 def id nil end |
#missing_barcodes ⇒ Object
92 93 94 95 96 |
# File 'app/models/labwhere_reception.rb', line 92 def = assets.to_set(&:machine_barcode) = assets.to_set(&:human_barcode) .delete_if { || .include?() || .include?() } end |
#new_record? ⇒ Boolean
36 37 38 |
# File 'app/models/labwhere_reception.rb', line 36 def new_record? true end |
#persisted? ⇒ Boolean
32 33 34 |
# File 'app/models/labwhere_reception.rb', line 32 def persisted? false end |
#save ⇒ Object
save attempts to perform the actions, and returns true if it was successful This maintains compatibility with rails rubocop:todo Metrics/MethodLength
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/labwhere_reception.rb', line 47 def save # rubocop:todo Metrics/AbcSize if user_code.blank? errors.add(:base, 'Please provide a valid user code.') return false end return false unless valid? begin scan = LabWhereClient::Scan.create( location_barcode: , user_code: user_code, labware_barcodes: ) unless scan.valid? # Prepend the errors with 'Labwhere' to make it clear where the error came from # This is important as you can get both Sequencescape and Labwhere errors of the same type # e.g. User does not exist labwhere_errors = scan.errors.map { |error| "LabWhere #{error}" } errors.add(:base, labwhere_errors) return false end rescue LabWhereClient::LabwhereException => e errors.add(:base, 'Could not connect to Labwhere.') return false end assets.each do |asset| asset.events.create_scanned_into_lab!(, user.login) BroadcastEvent::LabwareReceived.create!(seed: asset, user: user, properties: { location_barcode: }) end result = valid? @user_code = '' result end |
#user ⇒ Object
40 41 42 |
# File 'app/models/labwhere_reception.rb', line 40 def user @user ||= User.(@user_code) end |