<commit_before>require 'sequel'

class Sequel::Model
  extend OrmAdapter::ToAdapter
  plugin :active_model

  # Sequel: track models that inherit from Sequel::Model
  #         .descendants is used in Rails 3 and DM
  def self.descendants
    @@descendants ||= []
  end

  # Sequel: hook to track descendants
  def self.inherited(subclass)
    super
    descendants << subclass unless descendants.include?(subclass)
  end

  class OrmAdapter < ::OrmAdapter::Base

    # Gets a list of the available models for this adapter
    def self.model_classes
      ::Sequel::Model.descendants
    end

    def initialize(klass)
      @klass = klass
    end

    # Get a list of column/property/field names
    def column_names
      klass.columns
    end

    # Get an instance by id of the model. Raises an error if a model is not found.
    # This should comply with ActiveModel#to_key API, i.e.:
    #
    #   User.to_adapter.get!(@user.to_key) == @user
    #
    # Sequel: no built in finder/filter that raises an error so one is added here
    def get!(id)
      klass[wrap_key(id)] || raise(Error, "#{klass.name} not found with #{klass.primary_key} of #{wrap_key(id)}")
    end

    # Get an instance by id of the model. Returns nil if a model is not found.
    # This should comply with ActiveModel#to_key API, i.e.:
    #<commit_msg>Use Sequel Subclasses plugin to track descendents. (Suggested by mooman)<commit_after>require 'sequel'

class Sequel::Model
  extend OrmAdapter::ToAdapter
  plugin :active_model
  plugin :subclasses

  class OrmAdapter < ::OrmAdapter::Base

    # Gets a list of the available models for this adapter
    def self.model_classes
      Sequel::Model.descendents
    end

    def initialize(klass)
      @klass = klass
    end

    # Get a list of column/property/field names
    def column_names
      klass.columns
    end

    # Get an instance by id of the model. Raises an error if a model is not found.
    # This should comply with ActiveModel#to_key API, i.e.:
    #
    #   User.to_adapter.get!(@user.to_key) == @user
    #
    # Sequel: no built in finder/filter that raises an error so one is added here
    def get!(id)
      klass[wrap_key(id)] || raise(Error, "#{klass.name} not found with #{klass.primary_key} of #{wrap_key(id)}")
    end

    # Get an instance by id of the model. Returns nil if a model is not found.
    # This should comply with ActiveModel#to_key API, i.e.:
    #
{'fraction_non_alphanumeric': 0.0869386073341574, 'fraction_numerical': 0.00041203131437989287, 'mean_word_length': 2.9224555735056543, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4206235', 'n_tokens_mistral': 759, 'n_tokens_neox': 745, 'n_words': 273}