Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grant Hutchins & Peter Jaros
committed
Nov 17, 2010
1 parent
e898dfd
commit 6f1f154
Showing
3 changed files
with
53 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module PgSearch | ||
class Scope | ||
def initialize(name, scope_options_or_proc, model) | ||
@name = name | ||
@model = model | ||
@options_proc = build_options_proc(scope_options_or_proc) | ||
end | ||
|
||
def to_proc | ||
lambda { |*args| | ||
ScopeOptions.new(@name, @options_proc, @model, args).to_hash | ||
} | ||
end | ||
|
||
private | ||
|
||
def build_options_proc(scope_options_or_proc) | ||
case scope_options_or_proc | ||
when Proc | ||
scope_options_or_proc | ||
when Hash | ||
lambda { |query| | ||
scope_options_or_proc.reverse_merge(:query => query) | ||
} | ||
else | ||
raise ArgumentError, "A PgSearch scope expects a Proc or Hash for its options" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters