Sha256: f8185c489dc3b8cd63c947914af0cb59ff600eda0664d612409a93ef107567ab

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 Bytes

Contents

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

  def respond_to?(method, include_private = false)
    super || can_apply_scope?(method)
  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)
    search *sphinx_scopes[scope].call(*args)
  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

4 entries across 4 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.1 lib/thinking_sphinx/masks/scopes_mask.rb
thinking-sphinx-3.0.0 lib/thinking_sphinx/masks/scopes_mask.rb
thinking-sphinx-3.0.0.rc lib/thinking_sphinx/masks/scopes_mask.rb
thinking-sphinx-3.0.0.pre lib/thinking_sphinx/masks/scopes_mask.rb