forty_facets 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/forty_facets.rb +1 -0
- data/lib/forty_facets/facet_search.rb +5 -0
- data/lib/forty_facets/filter/custom_filter_definition.rb +26 -0
- data/lib/forty_facets/version.rb +1 -1
- data/test/smoke_test.rb +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b86da7ae3b989602b2dcbd37699c80466901e16
|
4
|
+
data.tar.gz: afd3024e01104aa310b23a4ac564fdd4c478c093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ef1428c9e97396a80f8c2577c7290b201208c603e4ade01b045ed2499ea8c137bb3a1b015a272787bd52979ccb29207accd274ce13593fb7012745e7a6e8ce5
|
7
|
+
data.tar.gz: 172f6758103dbea345a9bbd1ea67139fc4dff60da450a7c2285089ce528b452c67d80faa132add9a87ffd51ebf8ae4a34c4ec4259d4fb9b83a44d33cfd3095ea
|
data/README.md
CHANGED
@@ -67,6 +67,8 @@ class HomeController < ApplicationController
|
|
67
67
|
orders 'Title' => :title,
|
68
68
|
'price, cheap first' => "price asc",
|
69
69
|
'price, expensive first' => {price: :desc, title: :desc}
|
70
|
+
custom :for_manual_handling
|
71
|
+
|
70
72
|
end
|
71
73
|
|
72
74
|
def index
|
@@ -124,6 +126,7 @@ end
|
|
124
126
|
| facet | | creates a facetted filter on the specified model attribute (attribute or belongs_to) |
|
125
127
|
| range | | creates a range filter (param format 'FROM - TO') limiting result to entities with values in that range |
|
126
128
|
| orders | | takes a hash mapping a label to an argument that the active record `order` method can be called with to sort the result |
|
129
|
+
| custom | | doesnt affect the query directly, just handles the request param. access via @search.filter(:custom_filter).set(..) /@search.filter(:custom_filter).value |
|
127
130
|
|
128
131
|
## FAQ
|
129
132
|
|
data/lib/forty_facets.rb
CHANGED
@@ -9,6 +9,7 @@ require "forty_facets/filter"
|
|
9
9
|
require "forty_facets/filter_definition"
|
10
10
|
require "forty_facets/filter/range_filter_definition"
|
11
11
|
require "forty_facets/filter/text_filter_definition"
|
12
|
+
require "forty_facets/filter/custom_filter_definition"
|
12
13
|
require "forty_facets/filter/scope_filter_definition"
|
13
14
|
require "forty_facets/filter/facet_filter_definition"
|
14
15
|
require "forty_facets/filter/sql_facet_filter_definition"
|
@@ -15,6 +15,7 @@ module FortyFacets
|
|
15
15
|
# 'price, cheap first' => "price asc",
|
16
16
|
# 'price, expensive first' => {price: :desc, title: :desc},
|
17
17
|
# 'Title, reverse' => {order: "title desc", default: true}
|
18
|
+
# custom :for_manual_handling
|
18
19
|
#
|
19
20
|
# end
|
20
21
|
class FacetSearch
|
@@ -33,6 +34,10 @@ module FortyFacets
|
|
33
34
|
definitions << TextFilterDefinition.new(self, path, opts)
|
34
35
|
end
|
35
36
|
|
37
|
+
def custom(path, opts = {})
|
38
|
+
definitions << CustomFilterDefinition.new(self, path, opts)
|
39
|
+
end
|
40
|
+
|
36
41
|
def scope(path, opts = {})
|
37
42
|
definitions << ScopeFilterDefinition.new(self, path, opts)
|
38
43
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module FortyFacets
|
2
|
+
class CustomFilterDefinition < FilterDefinition
|
3
|
+
class CustomFilter < Filter
|
4
|
+
def build_scope
|
5
|
+
return Proc.new { |base| base } # the custom filter doesn alter the query at all
|
6
|
+
# but you can use it's state to modify the base_scope
|
7
|
+
# in your controller
|
8
|
+
end
|
9
|
+
|
10
|
+
def set(new_value)
|
11
|
+
new_params = search_instance.params || {}
|
12
|
+
|
13
|
+
new_params[definition.request_param] = new_value
|
14
|
+
search_instance.class.new_unwrapped(new_params, search_instance.root)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_filter(search_instance, value)
|
20
|
+
CustomFilter.new(self, search_instance, value)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
data/lib/forty_facets/version.rb
CHANGED
data/test/smoke_test.rb
CHANGED
@@ -29,6 +29,7 @@ class MovieSearch < FortyFacets::FacetSearch
|
|
29
29
|
{ name: "Classic" })
|
30
30
|
text [:studio, :description], name: 'Studio Description'
|
31
31
|
scope :classics, 'Name classics'
|
32
|
+
custom :needs_complex_filtering
|
32
33
|
end
|
33
34
|
|
34
35
|
class SmokeTest < Minitest::Test
|
@@ -273,4 +274,11 @@ class SmokeTest < Minitest::Test
|
|
273
274
|
assert search_with_scope.result.count < Movie.count, 'Activating the scope should yield a smaller set of movies'
|
274
275
|
end
|
275
276
|
|
277
|
+
def test_custom_filter
|
278
|
+
search = MovieSearch.new
|
279
|
+
new_search = search.filter(:needs_complex_filtering).set('foo')
|
280
|
+
|
281
|
+
assert_equal 'foo', new_search.filter(:needs_complex_filtering).value
|
282
|
+
end
|
283
|
+
|
276
284
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forty_facets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Axel Tetzlaff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/forty_facets.rb
|
116
116
|
- lib/forty_facets/facet_search.rb
|
117
117
|
- lib/forty_facets/filter.rb
|
118
|
+
- lib/forty_facets/filter/custom_filter_definition.rb
|
118
119
|
- lib/forty_facets/filter/facet_filter_definition.rb
|
119
120
|
- lib/forty_facets/filter/range_filter_definition.rb
|
120
121
|
- lib/forty_facets/filter/scope_filter_definition.rb
|