<commit_before># frozen_string_literal: true

class DataSource < FieldOptions
  def type_key
    self.class.type_key
  end

  def source_class
    raise NotImplementedError
  end

  def stored_type
    :integer
  end

  def foreign_field_name_suffix
    "_id"
  end

  def foreign_field_name(field_name)
    "#{field_name}#{foreign_field_name_suffix}"
  end

  def value_method
    :id
  end

  def text_method
    raise NotImplementedError
  end

  def value_for_preview_method
    raise NotImplementedError
  end

  def scoped_condition
    self.serializable_hash
  end

  def scoped_records
    self.class.scoped_records(scoped_condition)
  end

  def interpret_to(model, field_name, accessibility, _options = {})
    if source_class
      where_condition = scoped_condition.dup
      model.belongs_to field_name, -> { where(where_condition) }, class_name: source_class.to_s, optional: true
    end
  end

  class << self
    def type_key
      model_name.name.split("::").last.underscore
    end

    def scoped_records(_condition)
      raise NotImplementedError
    end
  end
end

require_dependency "data_sources"
<commit_msg>data source scoped records accept additional conditions<commit_after># frozen_string_literal: true

class DataSource < FieldOptions
  def type_key
    self.class.type_key
  end

  def source_class
    raise NotImplementedError
  end

  def stored_type
    :integer
  end

  def foreign_field_name_suffix
    "_id"
  end

  def foreign_field_name(field_name)
    "#{field_name}#{foreign_field_name_suffix}"
  end

  def value_method
    :id
  end

  def text_method
    raise NotImplementedError
  end

  def value_for_preview_method
    raise NotImplementedError
  end

  def scoped_condition
    self.serializable_hash
  end

  def scoped_records(**additional_condition)
    condition = scoped_condition.merge(additional_condition)
    self.class.scoped_records(condition)
  end

  def interpret_to(model, field_name, accessibility, _options = {})
    if source_class
      where_condition = scoped_condition.dup
      model.belongs_to field_name, -> { where(where_condition) }, class_name: source_class.to_s, optional: true
    end
  end

  class << self
    def type_key
      model_name.name.split("::").last.underscore
    end

    def scoped_records(_condition)
      raise NotImplementedError
    end
  end
end

require_dependency "data_sources"

{'fraction_non_alphanumeric': 0.0586756077116513, 'fraction_numerical': 0.0, 'mean_word_length': 3.581573896353167, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 5, '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': '5920288', 'n_tokens_mistral': 784, 'n_tokens_neox': 752, 'n_words': 172}