<commit_before># vi: ts=2:sts=2:et:sw=2 spell:spelllang=en

require 'lims-laboratory-app/laboratory/tube_rack/tube_rack_persistor'
require 'lims-core/persistence/sequel/persistor'

module Lims::LaboratoryApp
  module Laboratory
    # Not a tube_rack but a tube_rack persistor.
    class TubeRack
      class TubeInAnotherTubeRack < StandardError
      end

      class TubeRackSequelPersistor < TubeRackPersistor
        include Lims::Core::Persistence::Sequel::Persistor

        def self.table_name
          :tube_racks
        end

        # Delete the tube, rack association, but doesn't delete the tube.
        def delete_children(id, tube_rack)
          @session.tube_rack_slot.dataset.filter(:tube_rack_id => id).delete
        end
      end

      # Not a slot but a slot {Persistor}.
      class Slot 
        class SlotSequelPersitor < SlotPersistor
          include Lims::Core::Persistence::Sequel::Persistor
          def self.table_name
            :tube_rack_slots
          end

          def save_raw_association(tube_rack_id, tube_id, position)
            dataset.insert(:tube_rack_id => tube_rack_id,
              :position => position,
              :tube_id  => tube_id)
          end

          # Do a bulk load of aliquot and pass each to a block
          # @param tube_rack_id the id of the tube_rack to load.
          # @yieldparam [Integer] position
          # @yieldparam [Aliquot] aliquot
          def load_tubes(tube_rack_id)
            dataset.join(@session.tube.dataset, :id => :tube_id).filter(:tube_rack_id => tube_rack_id).each do |att|
              position = att.delete(:position)
              att.delete(:id)
              tube  = @session.tube.get_or_create_single_model(att[:tube_id], att)
              yield(position, tube)
            end
          end
        end
      end #class Slot
    end
  end
end
<commit_msg>Remove TubeInAnotherTubeRack definition from tube rack sequel persistor<commit_after># vi: ts=2:sts=2:et:sw=2 spell:spelllang=en

require 'lims-laboratory-app/laboratory/tube_rack/tube_rack_persistor'
require 'lims-core/persistence/sequel/persistor'

module Lims::LaboratoryApp
  module Laboratory
    # Not a tube_rack but a tube_rack persistor.
    class TubeRack
      class TubeRackSequelPersistor < TubeRackPersistor
        include Lims::Core::Persistence::Sequel::Persistor

        def self.table_name
          :tube_racks
        end

        # Delete the tube, rack association, but doesn't delete the tube.
        def delete_children(id, tube_rack)
          @session.tube_rack_slot.dataset.filter(:tube_rack_id => id).delete
        end
      end

      # Not a slot but a slot {Persistor}.
      class Slot 
        class SlotSequelPersitor < SlotPersistor
          include Lims::Core::Persistence::Sequel::Persistor
          def self.table_name
            :tube_rack_slots
          end

          def save_raw_association(tube_rack_id, tube_id, position)
            dataset.insert(:tube_rack_id => tube_rack_id,
              :position => position,
              :tube_id  => tube_id)
          end

          # Do a bulk load of aliquot and pass each to a block
          # @param tube_rack_id the id of the tube_rack to load.
          # @yieldparam [Integer] position
          # @yieldparam [Aliquot] aliquot
          def load_tubes(tube_rack_id)
            dataset.join(@session.tube.dataset, :id => :tube_id).filter(:tube_rack_id => tube_rack_id).each do |att|
              position = att.delete(:position)
              att.delete(:id)
              tube  = @session.tube.get_or_create_single_model(att[:tube_id], att)
              yield(position, tube)
            end
          end
        end
      end #class Slot
    end
  end
end

{'fraction_non_alphanumeric': 0.07996790585718107, 'fraction_numerical': 0.0016047071409467772, 'mean_word_length': 2.2864674868189807, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1118193', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1118, 'n_words': 267}