Sha256: f53919ea90a9cd5554b3f0817ba4381494562e7090a75276367a0358f232ac75

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

class ThinkingSphinx::Masks::ScopesMask
  def initialize(search)
    @search = search
  end

  def can_handle?(method)
    public_methods(false).include?(method) || can_apply_scope?(method)
  end

  def facets(query = nil, options = {})
    search = ThinkingSphinx.facets query, options
    ThinkingSphinx::Search::Merger.new(search).merge!(
      @search.query, @search.options
    )
  end

  def search(query = nil, options = {})
    query, options = nil, query if query.is_a?(Hash)
    ThinkingSphinx::Search::Merger.new(@search).merge! query, options
  end

  private

  def apply_scope(scope, *args)
    query, options = sphinx_scopes[scope].call(*args)
    search query, options
  end

  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

  def method_missing(method, *args, &block)
    apply_scope method, *args
  end

  def sphinx_scopes
    @search.options[:classes].first.sphinx_scopes
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.5 lib/thinking_sphinx/masks/scopes_mask.rb