-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
5 changed files
with
75 additions
and
1 deletion.
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
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,45 @@ | ||
module FortyFacets | ||
class ScopeFacetFilterDefinition < FilterDefinition | ||
|
||
attr_reader(:scopes) | ||
|
||
def initialize search, scopes, opts | ||
@search = search | ||
@scopes = Array(scopes).flatten.map(&:to_sym) | ||
@path = opts[:path] | ||
@path ||= @scopes.join('-') | ||
@options = opts | ||
end | ||
|
||
def request_param | ||
path | ||
end | ||
|
||
def build_filter(search_instance, param_value) | ||
ScopeFacetFilter.new(self, search_instance, param_value) | ||
end | ||
|
||
class ScopeFacetFilter < Filter | ||
def values | ||
@values ||= Array.wrap(value).sort.uniq | ||
end | ||
|
||
def build_scope | ||
return Proc.new { |base| base } if empty? | ||
|
||
return Proc.new do |base| | ||
# intersection of values and definition scopes | ||
scopes = values.map(&:to_sym) & definition.scopes | ||
scopes.inject(base) do |sum, scope| | ||
sum.send(scope) | ||
end | ||
end | ||
end | ||
|
||
def facet | ||
[] | ||
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
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