<commit_before>require "sequel/model"
module Delayed
  module Serialization
    module Sequel
      def self.configure(klass)
        klass.class_eval do
          if YAML.parser.class.name =~ /syck/i
            yaml_as "tag:ruby.yaml.org,2002:Sequel"
          end
        end
      end

      if YAML.parser.class.name =~ /syck/i
        module ClassMethods
          def yaml_new(klass, tag, val)
            pk = val["values"][klass.primary_key]
            klass[pk] ||
            raise(Delayed::DeserializationError, "Sequel Record not found, class: #{klass} , primary key: #{pk}")
          end
        end
      end

      module InstanceMethods
        if YAML.parser.class.name =~ /syck/i
          def to_yaml_properties
            ["@values"]
          end
        else
          def encode_with(coder)
            coder["values"] = @values
          end

          def init_with(coder)
            @values = coder["values"]
            reload
          rescue Sequel::Error
            raise Delayed::DeserializationError, "Sequel Record not found, class: #{self.class.name} , primary key: #{pk}"
          end
        end
      end
    end
  end
end

Sequel::Model.plugin Delayed::Serialization::Sequel
<commit_msg>Use fully qualified name when rescuing Sequel::Error<commit_after>require "sequel/model"
module Delayed
  module Serialization
    module Sequel
      def self.configure(klass)
        klass.class_eval do
          if YAML.parser.class.name =~ /syck/i
            yaml_as "tag:ruby.yaml.org,2002:Sequel"
          end
        end
      end

      if YAML.parser.class.name =~ /syck/i
        module ClassMethods
          def yaml_new(klass, tag, val)
            pk = val["values"][klass.primary_key]
            klass[pk] ||
            raise(Delayed::DeserializationError, "Sequel Record not found, class: #{klass} , primary key: #{pk}")
          end
        end
      end

      module InstanceMethods
        if YAML.parser.class.name =~ /syck/i
          def to_yaml_properties
            ["@values"]
          end
        else
          def encode_with(coder)
            coder["values"] = @values
          end

          def init_with(coder)
            @values = coder["values"]
            reload
          rescue ::Sequel::Error
            raise Delayed::DeserializationError, "Sequel Record not found, class: #{self.class.name} , primary key: #{pk}"
          end
        end
      end
    end
  end
end

Sequel::Model.plugin Delayed::Serialization::Sequel

{'fraction_non_alphanumeric': 0.09580838323353294, 'fraction_numerical': 0.0031936127744510976, 'mean_word_length': 1.7937569676700111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4720989', 'n_tokens_mistral': 753, 'n_tokens_neox': 737, 'n_words': 178}