Class: LibPoolNormTubeGenerator

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/lib_pool_norm_tube_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(barcode, user, study) ⇒ LibPoolNormTubeGenerator

Returns a new instance of LibPoolNormTubeGenerator


12
13
14
15
16
# File 'app/models/lib_pool_norm_tube_generator.rb', line 12

def initialize(barcode, user, study)
  self.plate = barcode
  @user = user
  @study = study
end

Instance Attribute Details

#asset_groupObject (readonly)

Returns the value of attribute asset_group


5
6
7
# File 'app/models/lib_pool_norm_tube_generator.rb', line 5

def asset_group
  @asset_group
end

#plateObject

Returns the value of attribute plate


4
5
6
# File 'app/models/lib_pool_norm_tube_generator.rb', line 4

def plate
  @plate
end

#studyObject (readonly)

Returns the value of attribute study


5
6
7
# File 'app/models/lib_pool_norm_tube_generator.rb', line 5

def study
  @study
end

#userObject (readonly)

Returns the value of attribute user


5
6
7
# File 'app/models/lib_pool_norm_tube_generator.rb', line 5

def user
  @user
end

Instance Method Details

#create!Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/lib_pool_norm_tube_generator.rb', line 39

def create!
  if valid?
    begin
      ActiveRecord::Base.transaction do
        lib_pool_tubes.each do |tube|
          pass_and_complete(tube)
          pass_and_complete(create_lib_pool_norm_tube(tube))
        end

        @asset_group = AssetGroup.create!(assets: destination_tubes.map(&:receptacle), study: study, name: "#{plate.human_barcode}_qc_completed_tubes")
      end
      true
    rescue => e
      Rails.logger.error("Pool generation error: #{e.message}")
      Rails.logger.error(e.backtrace)
      false
    end
  end
end

#destination_tubesObject


35
36
37
# File 'app/models/lib_pool_norm_tube_generator.rb', line 35

def destination_tubes
  @destination_tubes ||= []
end

#lib_pool_tubesObject


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

def lib_pool_tubes
  @lib_pool_tubes ||= plate.children.select { |c| c.is_a?(StockMultiplexedLibraryTube) }
                           .reject { |tube| tube.state == 'failed' || tube.state == 'qc_complete' || tube.state == 'cancelled' }
end

#set_plate(barcode) ⇒ Object


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

def set_plate(barcode)
  Plate.with_barcode(barcode).includes(wells: { requests: [:request_type, :target_asset] }).first
end

#transfer_templateObject


18
19
20
# File 'app/models/lib_pool_norm_tube_generator.rb', line 18

def transfer_template
  @transfer_template ||= TransferTemplate.find_by!(transfer_class_name: 'Transfer::BetweenTubesBySubmission')
end