Sha256: 538f1b3483950f7b2395d0e82b9d5ec90e20a4fdbc806954ea24fe4d21df7651

Contents?: true

Size: 722 Bytes

Versions: 3

Compression:

Stored size: 722 Bytes

Contents

module PgSearch
  class Scope
    def initialize(name, model, scope_options_or_proc)
      @name = name
      @model = model
      @options_proc = build_options_proc(scope_options_or_proc)
    end

    def build_relation(*args)
      config = Configuration.new(@options_proc.call(*args), @model)
      scope_options = ScopeOptions.new(@name, config)
      scope_options.apply(@model)
    end

    private

    def build_options_proc(scope_options)
      return scope_options if scope_options.respond_to?(:call)

      unless scope_options.respond_to?(:merge)
        raise ArgumentError, "pg_search_scope expects a Hash or Proc"
      end

      lambda { |query| {:query => query}.merge(scope_options) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pg_search-0.5.4 lib/pg_search/scope.rb
pg_search-0.5.3 lib/pg_search/scope.rb
pg_search-0.5.2 lib/pg_search/scope.rb