class ThinkingSphinx::Masks::ScopesMask

Public Class Methods

new(search) click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 4
def initialize(search)
  @search = search
end

Public Instance Methods

can_handle?(method) click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 8
def can_handle?(method)
  public_methods(false).include?(method) || can_apply_scope?(method)
end
facets(query = nil, options = {}) click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 12
def facets(query = nil, options = {})
  search = ThinkingSphinx.facets query, options
  ThinkingSphinx::Search::Merger.new(search).merge!(
    @search.query, @search.options
  )
end
search_for_ids(query = nil, options = {}) click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 24
def search_for_ids(query = nil, options = {})
  query, options = nil, query if query.is_a?(Hash)
  search query, options.merge(:ids_only => true)
end

Private Instance Methods

apply_scope(scope, *args) click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 31
def apply_scope(scope, *args)
  query, options = sphinx_scopes[scope].call(*args)
  search query, options
end
can_apply_scope?(scope) click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 36
def can_apply_scope?(scope)
  @search.options[:classes].present?    &&
  @search.options[:classes].length == 1 &&
  @search.options[:classes].first.respond_to?(:sphinx_scopes) &&
  sphinx_scopes[scope].present?
end
method_missing(method, *args, &block) click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 43
def method_missing(method, *args, &block)
  apply_scope method, *args
end
sphinx_scopes() click to toggle source
# File lib/thinking_sphinx/masks/scopes_mask.rb, line 47
def sphinx_scopes
  @search.options[:classes].first.sphinx_scopes
end