seeker 0.3.0 → 0.3.1
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 +39 -32
- data/lib/seeker/base.rb +8 -8
- data/lib/seeker/form_helper.rb +1 -1
- data/lib/seeker/railtie.rb +0 -1
- data/lib/seeker/version.rb +1 -1
- metadata +1 -2
- data/lib/seeker/route_helper.rb +0 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d85d2d7bc5903bd23dcae55d1aeb33c287a6d65
|
|
4
|
+
data.tar.gz: bd99e27968cead135be7dd640038a366dc57e93e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d1fb546ac2cbca8f4e9ae9d07b9bcddeaa6fab00abed27df94e29338a3e1db9e3e5b16ab32009f966acb67e665ca35bde0519a24387ba2f9bfbc33ac5548a54
|
|
7
|
+
data.tar.gz: bf799b2bd542fb4a068dac9f9493a909e472e5730d88a0793371b353032cc2780cfb5ae3a9918cc173f785a9fd61afec26cdfd184f9635ce5dc91160cd9f8bbd
|
data/README.md
CHANGED
|
@@ -13,52 +13,59 @@ Right now it supports only [sunspot](https://github.com/sunspot/sunspot) and was
|
|
|
13
13
|
|
|
14
14
|
Given you have Product model:
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
```ruby
|
|
17
|
+
class Product < ActiveRecord::Base
|
|
18
|
+
mount_searcher ProductSearcher
|
|
19
|
+
end
|
|
20
|
+
```
|
|
19
21
|
|
|
20
22
|
Create corresponding searcher:
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
```ruby
|
|
25
|
+
# app/searchers/product_searcher.rb
|
|
26
|
+
class ProductSearcher < Seeker::Base
|
|
27
|
+
attr_accessor :name, :max_price
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
searchable do
|
|
30
|
+
text :name
|
|
31
|
+
integer :price
|
|
32
|
+
end
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
def search(query)
|
|
35
|
+
query.fulltext(:name, @name) if @name.present?
|
|
36
|
+
query.with(:price).less_than_or_equal_to(@max_price) if @max_price.present?
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
```
|
|
36
40
|
|
|
37
41
|
Use it in your controller:
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
```ruby
|
|
44
|
+
class ProductsController < ApplicationController
|
|
45
|
+
def index
|
|
46
|
+
@searcher = Product.searcher params[:product]
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
```
|
|
44
50
|
|
|
45
51
|
And use it in your view with form helper, just like model:
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
```slim
|
|
54
|
+
# app/views/products/index.html.slim
|
|
55
|
+
= form_for @searcher do |f|
|
|
56
|
+
= f.label :name
|
|
57
|
+
= f.text_field :name
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
= f.label :max_price
|
|
60
|
+
= f.number_field :max_price
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
h1 Search results
|
|
58
|
-
ul
|
|
59
|
-
= @searcher.results.each do |product|
|
|
60
|
-
li #{product.name} - #{product.price}
|
|
62
|
+
= f.submit
|
|
61
63
|
|
|
64
|
+
h1 Search results
|
|
65
|
+
ul
|
|
66
|
+
= @searcher.results.each do |product|
|
|
67
|
+
li #{product.name} - #{product.price}
|
|
68
|
+
```
|
|
62
69
|
|
|
63
70
|
## TODO
|
|
64
71
|
|
data/lib/seeker/base.rb
CHANGED
|
@@ -9,15 +9,13 @@ class Seeker::Base
|
|
|
9
9
|
|
|
10
10
|
def initialize(params={})
|
|
11
11
|
assign params
|
|
12
|
-
|
|
13
|
-
super()
|
|
14
12
|
end
|
|
15
13
|
|
|
16
14
|
def assign(params)
|
|
17
15
|
params.each do |attr, value|
|
|
18
16
|
self.public_send("#{attr}=", value)
|
|
19
|
-
end
|
|
20
|
-
|
|
17
|
+
end
|
|
18
|
+
|
|
21
19
|
self
|
|
22
20
|
end
|
|
23
21
|
|
|
@@ -45,11 +43,13 @@ class Seeker::Base
|
|
|
45
43
|
seek.results
|
|
46
44
|
end
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
# force plural route in ActionDispatch::Routing::PolymorphicRoutes#polymorphic_url
|
|
47
|
+
def persisted?
|
|
48
|
+
false
|
|
50
49
|
end
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
# for ActionController::RecordIdentifier#record_key_for_dom_id
|
|
52
|
+
def to_key
|
|
53
|
+
nil
|
|
54
54
|
end
|
|
55
55
|
end
|
data/lib/seeker/form_helper.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Seeker::FormHelper
|
|
|
5
5
|
|
|
6
6
|
as = options[:as]
|
|
7
7
|
# added searcher
|
|
8
|
-
action, method = if object.
|
|
8
|
+
action, method = if object.class < Seeker::Base
|
|
9
9
|
[:search, :get]
|
|
10
10
|
else
|
|
11
11
|
object.respond_to?(:persisted?) && object.persisted? ? [:edit, :put] : [:new, :post]
|
data/lib/seeker/railtie.rb
CHANGED
data/lib/seeker/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: seeker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Szymon Przybył
|
|
@@ -56,7 +56,6 @@ files:
|
|
|
56
56
|
- lib/seeker/base.rb
|
|
57
57
|
- lib/seeker/form_helper.rb
|
|
58
58
|
- lib/seeker/railtie.rb
|
|
59
|
-
- lib/seeker/route_helper.rb
|
|
60
59
|
- lib/seeker/searcher_mounter.rb
|
|
61
60
|
- lib/seeker/version.rb
|
|
62
61
|
- seeker.gemspec
|
data/lib/seeker/route_helper.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
module ActionDispatch::Routing::PolymorphicRoutes
|
|
2
|
-
def polymorphic_url(record_or_hash_or_array, options = {})
|
|
3
|
-
if record_or_hash_or_array.kind_of?(Array)
|
|
4
|
-
record_or_hash_or_array = record_or_hash_or_array.compact
|
|
5
|
-
if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy)
|
|
6
|
-
proxy = record_or_hash_or_array.shift
|
|
7
|
-
end
|
|
8
|
-
record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
record = extract_record(record_or_hash_or_array)
|
|
12
|
-
record = convert_to_model(record)
|
|
13
|
-
|
|
14
|
-
args = Array === record_or_hash_or_array ?
|
|
15
|
-
record_or_hash_or_array.dup :
|
|
16
|
-
[ record_or_hash_or_array ]
|
|
17
|
-
|
|
18
|
-
inflection = if options[:action] && options[:action].to_s == "new"
|
|
19
|
-
args.pop
|
|
20
|
-
:singular
|
|
21
|
-
# added searcher
|
|
22
|
-
elsif (record.respond_to?(:persisted?) && !record.persisted? || record.respond_to?(:searcher?))
|
|
23
|
-
args.pop
|
|
24
|
-
:plural
|
|
25
|
-
elsif record.is_a?(Class)
|
|
26
|
-
args.pop
|
|
27
|
-
:plural
|
|
28
|
-
else
|
|
29
|
-
:singular
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
args.delete_if {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
|
|
33
|
-
named_route = build_named_route_call(record_or_hash_or_array, inflection, options)
|
|
34
|
-
|
|
35
|
-
url_options = options.except(:action, :routing_type)
|
|
36
|
-
unless url_options.empty?
|
|
37
|
-
args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
args.collect! { |a| convert_to_model(a) }
|
|
41
|
-
|
|
42
|
-
(proxy || self).send(named_route, *args)
|
|
43
|
-
end
|
|
44
|
-
end
|