<commit_before>require 'lims-core/persistence/persist_association_trait'
require 'lims-core/persistence/sequel/persistor'
module Lims::LaboratoryApp
  module Laboratory
    module Container
      module ContainerPersistorTrait
        as_trait do |args|
          element = args[:element]
          parent_class = self.name.split('::').last
          parent = parent_class.snakecase
          class_name = element.to_s.camelcase
          table_name = args[:table_name]
          class_eval <<-EOC
      (does "lims/core/persistence/persistable", :children => [
          {:name => :#{element}, :deletable => true }
        ]).class_eval do


        def children_#{element}(resource, children)
          resource.content.each_with_index do |#{element}, position|
            #{element}.each do |aliquot|
              #{element} = self.class::#{class_name}.new(resource, position, aliquot)
              state = @session.state_for(#{element})
              state.resource = #{element}
              children << #{element}
            end
          end
        end

        association_class "#{class_name}" do
          attribute :#{parent}, #{parent_class}, :relation => :parent
          attribute :position, Fixnum
          attribute :aliquot, Aliquot, :relation => :parent

          def on_load
            @#{parent}[@position] << @aliquot
          end

          def invalid?
            !@#{parent}[@position].include?(@aliquot)
          end
        end

        #{
          if table_name
            "
        class self::#{class_name}
          class #{class_name}SequelPersistor < self::#{class_name}Persistor
            include Lims::Core::Persistence::Sequel::Persistor
            def self.table_name
              :#{table_name}
            end
          end
        end
        "
      end<commit_msg>skip container parent in parents_from_attributes.<commit_after>require 'lims-core/persistence/persist_association_trait'
require 'lims-core/persistence/sequel/persistor'
module Lims::LaboratoryApp
  module Laboratory
    module Container
      module ContainerPersistorTrait
        as_trait do |args|
          element = args[:element]
          parent_class = self.name.split('::').last
          parent = parent_class.snakecase
          class_name = element.to_s.camelcase
          table_name = args[:table_name]
          class_eval <<-EOC
      (does "lims/core/persistence/persistable", :children => [
          {:name => :#{element}, :deletable => true }
        ]).class_eval do


        def children_#{element}(resource, children)
          resource.content.each_with_index do |#{element}, position|
            #{element}.each do |aliquot|
              #{element} = self.class::#{class_name}.new(resource, position, aliquot)
              state = @session.state_for(#{element})
              state.resource = #{element}
              children << #{element}
            end
          end
        end

        association_class "#{class_name}" do
          attribute :#{parent}, #{parent_class}, :relation => :parent, :skip_parents_for_attributes => true
          attribute :position, Fixnum
          attribute :aliquot, Aliquot, :relation => :parent

          def on_load
            @#{parent}[@position] << @aliquot
          end

          def invalid?
            !@#{parent}[@position].include?(@aliquot)
          end
        end

        #{
          if table_name
            "
        class self::#{class_name}
          class #{class_name}SequelPersistor < self::#{class_name}Persistor
            include Lims::Core::Persistence::Sequel::Persistor
            def self.table_name
              :#{table_name}
            end
          end
        end
        "
      end
{'fraction_non_alphanumeric': 0.11209677419354838, 'fraction_numerical': 0.0, 'mean_word_length': 2.008084074373484, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 14, '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': '5529423', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1031, 'n_words': 207}