Module: Heron::Factories::Concerns::ForeignBarcodes

Included in:
Plate, Tube, TubeRack
Defined in:
app/models/heron/factories/concerns/foreign_barcodes.rb

Overview

A foreign barcode is a barcode that has been externally set, that is added as another extra barcode for the labware referred. This module adds validation and processing methods for this barcodes

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



11
12
13
14
15
16
17
18
# File 'app/models/heron/factories/concerns/foreign_barcodes.rb', line 11

def self.included(klass)
  klass.instance_eval do
    attr_accessor :barcode

    validates :barcode, presence: true
    validate :check_barcode_format, :check_foreign_barcode_unique
  end
end

Instance Method Details

#barcode_formatObject



20
21
22
# File 'app/models/heron/factories/concerns/foreign_barcodes.rb', line 20

def barcode_format
  Barcode.matching_barcode_format(barcode)
end

#check_barcode_formatObject



24
25
26
27
28
# File 'app/models/heron/factories/concerns/foreign_barcodes.rb', line 24

def check_barcode_format
  return if barcode_format.present?

  errors.add(:base, "The barcode '#{barcode}' is not a recognised format.")
end

#check_foreign_barcode_uniqueObject



30
31
32
33
34
# File 'app/models/heron/factories/concerns/foreign_barcodes.rb', line 30

def check_foreign_barcode_unique
  return unless Barcode.exists_for_format?(barcode_format, barcode)

  errors.add(:base, "The barcode '#{barcode}' is already in use.")
end