<commit_before>require 'active_support/deprecation'

module ActiveRecord
  module DeprecatedFinders
    class ScopeWrapper
      def self.wrap(klass, scope)
        if scope.is_a?(Hash)
          ActiveSupport::Deprecation.warn(
            "Calling #scope or #default_scope with a hash is deprecated. Please use a lambda " \
            "containing a scope. E.g. scope :red, -> { where(color: 'red') }"
          )

          new(klass, scope)
        elsif !scope.is_a?(Relation) && scope.respond_to?(:call)
          new(klass, scope)
        else
          scope
        end
      end

      def initialize(klass, scope)
        @klass = klass
        @scope = scope
      end

      def call(*args)
        if @scope.respond_to?(:call)
          result = @scope.call(*args)

          if result.is_a?(Hash)
            ActiveSupport::Deprecation.warn(
              "Return a hash from a #scope or #default_scope block is deprecated. Please " \
              "return an actual scope object instead. E.g. scope :red, -> { where(color: 'red') } "\
              "rather than scope :red, -> { { conditions: { color: 'red' } } }."
            )
          end
        else
          result = @scope
        end

        if result.is_a?(Hash)
          @klass.unscoped.apply_finder_options(result)
        else
          result
        end
      end
    end

    def default_scope(scope = {}, &block)
      if block_given?
        super ScopeWrapper.new(self, block), &nil
      else
        super ScopeWrapper.wrap(self, scope)
      end
    end

    def scoped(options = nil)
      if options && (options.keys & [:conditions, :include, :extend]).any?
        super().apply_finder_options(options)
      else
        super
      end<commit_msg>show the proc#inspect to help people find it<commit_after>require 'active_support/deprecation'

module ActiveRecord
  module DeprecatedFinders
    class ScopeWrapper
      def self.wrap(klass, scope)
        if scope.is_a?(Hash)
          ActiveSupport::Deprecation.warn(
            "Calling #scope or #default_scope with a hash is deprecated. Please use a lambda " \
            "containing a scope. E.g. scope :red, -> { where(color: 'red') }"
          )

          new(klass, scope)
        elsif !scope.is_a?(Relation) && scope.respond_to?(:call)
          new(klass, scope)
        else
          scope
        end
      end

      def initialize(klass, scope)
        @klass = klass
        @scope = scope
      end

      def call(*args)
        if @scope.respond_to?(:call)
          result = @scope.call(*args)

          if result.is_a?(Hash)
            ActiveSupport::Deprecation.warn(
              "Returning a hash from a #scope or #default_scope block is deprecated. Please " \
              "return an actual scope object instead. E.g. scope :red, -> { where(color: 'red') } " \
              "rather than scope :red, -> { { conditions: { color: 'red' } } }. (Inspecting the proc " \
              "gives #{@scope.inspect} - this may help you find it."
            )
          end
        else
          result = @scope
        end

        if result.is_a?(Hash)
          @klass.unscoped.apply_finder_options(result)
        else
          result
        end
      end
    end

    def default_scope(scope = {}, &block)
      if block_given?
        super ScopeWrapper.new(self, block), &nil
      else
        super ScopeWrapper.wrap(self, scope)
      end
    end

    def scoped(options = nil)
      if options && (options.keys & [:conditions, :include, :extend]).any?
        super().apply_finder_options(options)
      else
        super
      end
{'fraction_non_alphanumeric': 0.10398230088495575, 'fraction_numerical': 0.0, 'mean_word_length': 1.797370456303171, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4545167', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1056, 'n_words': 285}