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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6ac131236feedf73a1d6a76f642f4ba48631073
4
- data.tar.gz: 7743dfe28328833f1e2936d87d532c5699374a42
3
+ metadata.gz: 5d85d2d7bc5903bd23dcae55d1aeb33c287a6d65
4
+ data.tar.gz: bd99e27968cead135be7dd640038a366dc57e93e
5
5
  SHA512:
6
- metadata.gz: e76a8dc7b3c2eeb2571a6dfc3f213477c417a71aede9e904e4a9e1cb064f2d3241d30d549e16420e709348c8157736638999e1d0ccb10607f2af4992f142be66
7
- data.tar.gz: 61f5ba6cfcfb9d96d167db376b36c4b818016caf3f303ba20ab9370e1ea68ec606511e53170cc6ed42db9d408a2b29f53fe5721f8a43aaff21faef4e34c85fa0
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
- class Product < ActiveRecord::Base
17
- mount_searcher ProductSearcher
18
- end
16
+ ```ruby
17
+ class Product < ActiveRecord::Base
18
+ mount_searcher ProductSearcher
19
+ end
20
+ ```
19
21
 
20
22
  Create corresponding searcher:
21
23
 
22
- # app/searchers/product_searcher.rb
23
- class ProductSearcher < Seeker::Base
24
- attr_accessor :name, :max_price
24
+ ```ruby
25
+ # app/searchers/product_searcher.rb
26
+ class ProductSearcher < Seeker::Base
27
+ attr_accessor :name, :max_price
25
28
 
26
- searchable do
27
- text :name
28
- integer :price
29
- end
29
+ searchable do
30
+ text :name
31
+ integer :price
32
+ end
30
33
 
31
- def search(query)
32
- query.fulltext(:name, @name) if @name.present?
33
- query.with(:price).less_than_or_equal_to(@max_price) if @max_price.present?
34
- end
35
- end
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
- class ProductsController < ApplicationController
40
- def index
41
- @searcher = Product.searcher params[:product]
42
- end
43
- end
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
- # app/views/products/index.html.slim
48
- = form_for @searcher do |f|
49
- = f.label :name
50
- = f.text_field :name
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
- = f.label :max_price
53
- = f.number_field :max_price
59
+ = f.label :max_price
60
+ = f.number_field :max_price
54
61
 
55
- = f.submit
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
 
@@ -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 if params
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
- def to_key
49
- nil
46
+ # force plural route in ActionDispatch::Routing::PolymorphicRoutes#polymorphic_url
47
+ def persisted?
48
+ false
50
49
  end
51
50
 
52
- def searcher?
53
- true
51
+ # for ActionController::RecordIdentifier#record_key_for_dom_id
52
+ def to_key
53
+ nil
54
54
  end
55
55
  end
@@ -5,7 +5,7 @@ module Seeker::FormHelper
5
5
 
6
6
  as = options[:as]
7
7
  # added searcher
8
- action, method = if object.respond_to?(:searcher?)
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]
@@ -1,5 +1,4 @@
1
1
  require 'seeker/form_helper'
2
- require 'seeker/route_helper'
3
2
  require 'seeker/searcher_mounter'
4
3
 
5
4
  module Seeker
@@ -1,3 +1,3 @@
1
1
  module Seeker
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
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.0
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
@@ -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