Sha256: 086898173db057508d9fbf6ac07889083d0fca7e7b4caf5679bd1da3681031da

Contents?: true

Size: 758 Bytes

Versions: 15

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true

module ThinkingSphinx::Scopes
  extend ActiveSupport::Concern

  module ClassMethods
    def default_sphinx_scope(scope_name = nil)
      return @default_sphinx_scope unless scope_name

      @default_sphinx_scope = scope_name
    end

    def sphinx_scope(name, &block)
      sphinx_scopes[name] = block
    end

    def sphinx_scopes
      @sphinx_scopes ||= {}
    end

    private

    def method_missing(method, *args, &block)
      return super unless sphinx_scopes.keys.include?(method)

      query, options = sphinx_scopes[method].call(*args)
      search query, (options || {})
    end

    def respond_to_missing?(method, include_private = false)
      super || sphinx_scopes.keys.include?(method)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/scopes.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/scopes.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/scopes.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/scopes.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/scopes.rb