<commit_before># encoding: utf-8

module FriendlyId::SluggableClassMethods

  include FriendlyId::Helpers

  def self.extended(base) #:nodoc:#

    class << base
      alias_method_chain :find_one, :friendly
      alias_method_chain :find_some, :friendly
      alias_method_chain :validate_find_options, :friendly
    end

  end

  # Finds a single record using the friendly id, or the record's id.
  def find_one_with_friendly(id_or_name, options) #:nodoc:#

    scope = options.delete(:scope)
    return find_one_without_friendly(id_or_name, options) if id_or_name.is_a?(Integer)

    find_options = {:select => "#{self.table_name}.*"}
    find_options[:joins] = :slugs unless options[:include] && [*options[:include]].flatten.include?(:slugs)

    name, sequence = Slug.parse(id_or_name)

    find_options[:conditions] = {
      "#{Slug.table_name}.name"     => name,
      "#{Slug.table_name}.scope"    => scope,
      "#{Slug.table_name}.sequence" => sequence
    }

    result = with_scope(:find => find_options) { find_initial(options) }

    if result
      result.finder_slug_name = id_or_name
    elsif id_or_name.to_i.to_s != id_or_name
      raise ActiveRecord::RecordNotFound
    else
      result = find_one_without_friendly id_or_name, options
    end

    result
  rescue ActiveRecord::RecordNotFound => e

    if friendly_id_options[:scope]
      if !scope
        e.message << "; expected scope but got none"
      else
        e.message << " and scope=#{scope}"
      end
    end

    raise e

  end

  # Finds multiple records using the friendly ids, or the records' ids.
  def find_some_with_friendly(ids_and_names, options) #:nodoc:#

    slugs, ids = get_slugs_and_ids(ids_and_names, options)
    results = []

    find_options = {:select => "#{self.table_name}.*"}
    find_options[:joins] = :slugs unless options[:include] && [*options[:include]].flatten.include?(:slugs)<commit_msg>Raise a new ActiveRecord::RecordNotFound rather than append to the error's message'; 1.9.1 freezes exception messages.<commit_after># encoding: utf-8

module FriendlyId::SluggableClassMethods

  include FriendlyId::Helpers

  def self.extended(base) #:nodoc:#

    class << base
      alias_method_chain :find_one, :friendly
      alias_method_chain :find_some, :friendly
      alias_method_chain :validate_find_options, :friendly
    end

  end

  # Finds a single record using the friendly id, or the record's id.
  def find_one_with_friendly(id_or_name, options) #:nodoc:#

    scope = options.delete(:scope)
    return find_one_without_friendly(id_or_name, options) if id_or_name.is_a?(Integer)

    find_options = {:select => "#{self.table_name}.*"}
    find_options[:joins] = :slugs unless options[:include] && [*options[:include]].flatten.include?(:slugs)

    name, sequence = Slug.parse(id_or_name)

    find_options[:conditions] = {
      "#{Slug.table_name}.name"     => name,
      "#{Slug.table_name}.scope"    => scope,
      "#{Slug.table_name}.sequence" => sequence
    }

    result = with_scope(:find => find_options) { find_initial(options) }

    if result
      result.finder_slug_name = id_or_name
    elsif id_or_name.to_i.to_s != id_or_name
      raise ActiveRecord::RecordNotFound
    else
      result = find_one_without_friendly id_or_name, options
    end

    result
  rescue ActiveRecord::RecordNotFound => e

    if friendly_id_options[:scope]
      if !scope
        raise ActiveRecord::RecordNotFound.new("%s; expected scope but got none" % e.message)
        # e.message << "; expected scope but got none"
      else
        raise ActiveRecord::RecordNotFound.new("%s and scope=#{scope}" % e.message)
        # e.message << " and scope=#{scope}"
      end
    end

    raise e

  end

  # Finds multiple records using the friendly ids, or the records' ids.
  def find_some_with_friendly(ids_and_names, options) #:nodoc:#

    slugs, ids = get_slugs_and_ids(ids_and_names, options)
    results = []

    find_options = {:select => "#{self.table_name}.*"}
    find_options[:joins] = :slugs unless options[:include] && [*options[:include]].flatten.include?(:slugs)
{'fraction_non_alphanumeric': 0.11820619059224957, 'fraction_numerical': 0.0012186205215695832, 'mean_word_length': 3.6583427922814984, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '6635155', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1310, 'n_words': 294}