Sha256: 227b0150c478a8fc3b96930386622f27d12ef1609b1122fa41064a61f3bcd19d

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 Bytes

Contents

module Searchlogic
  module ActiveRecord
    # The internals to ActiveRecord like to do scopes.include?(scope_name). And this is how they check for the existence
    # of scopes, which is terrible. The problem is that searchlogic scopes are dynamically created. So the only solution
    # is to override the include? method for the scopes hash, try to create the named scope, and then check it again.
    # This shouldn't effect performance because once its created it never gets called again. I also cache failed names
    # so we don't try to create them again.
    module Scope
      def scopes
        read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {}.tap do |h|
          h.instance_eval <<-eval
            def include?(key)
              result = super
              return result if result
              super
            end
          eval
        end)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
searchlogic-2.5.0 lib/searchlogic/active_record/scope.rb