simple_searchable 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -5
- data/lib/simple_searchable/version.rb +1 -1
- data/simple_searchable.gemspec +1 -1
- metadata +16 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07f09bcd6be2d696361577ec3aba42f9ce290c2
|
4
|
+
data.tar.gz: 702622cc97bd72ce5ef8e2f5b10196374bb71ded
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27bf6590e2b6f9550b06eb15a07339053c962225353434543b9936534d948e7542bb22580b3e03bc00d03cdf9a5ebbf45018a5266fd4cf4fee92fb25fcc4cd5c
|
7
|
+
data.tar.gz: 10e6740913c3c25b339fa8eaf11a99b1d10a59acc8234ffa069f8452151dfa386961f95356bfcc56b780f01c51461430150651bd98e5bcb9ccc7a5cd208721dc
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SimpleSearchable
|
2
2
|
|
3
|
-
|
3
|
+
This gem adds the utility methods for a basic ActiveRecord search/filtering pattern explained [here](http://www.wordofmike.net/j/easy-active-record-search-pattern).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -14,13 +14,52 @@ And then execute:
|
|
14
14
|
|
15
15
|
$ bundle
|
16
16
|
|
17
|
-
|
17
|
+
## Usage
|
18
18
|
|
19
|
-
|
19
|
+
To use, bundle the gem with your project and call `searchable_by` from your model(s):
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
class Religion < ActiveRecord::Base
|
23
|
+
searchable_by :monotheiestic, :originated_in
|
24
|
+
|
25
|
+
def self.originated_in(continents)
|
26
|
+
where(originating_continent: continents)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.monotheistic(true_false)
|
30
|
+
where(monotheistic: true_false)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Now write a search form which uses the method names as parameter keys:
|
36
|
+
|
37
|
+
```erb
|
38
|
+
<%= form_tag religions_path do %>
|
39
|
+
<%= fields_for :religion_filters do |f| %>
|
40
|
+
<%= f.label do %>
|
41
|
+
Monotheistic? <%= f.check_box :monotheistic, {}, true, false %>
|
42
|
+
<% end %>
|
43
|
+
|
44
|
+
<%= f.label :originated_in, "Originated" %>
|
45
|
+
<%= f.select :originated_in, LOCATIONS %>
|
46
|
+
<% end %>
|
47
|
+
|
48
|
+
<%= submit_tag "Search Religions" %>
|
49
|
+
<% end %>
|
50
|
+
```
|
51
|
+
|
52
|
+
And get your controller to use `search`:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class ReligionsController < ApplicationController
|
56
|
+
def index
|
57
|
+
@religions = Religion.search(params[:religion_filters])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
22
61
|
|
23
|
-
|
62
|
+
If you want to add a new filter, add the scope to the AR class and list it in `searchable_by`, then add an input to your form.
|
24
63
|
|
25
64
|
## Contributing
|
26
65
|
|
data/simple_searchable.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_runtime_dependency "activerecord", "
|
20
|
+
spec.add_runtime_dependency "activerecord", "< 6", ">= 4.0"
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.7"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_searchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "<"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
- -
|
19
|
+
version: '6'
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '4.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - "<"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
30
|
-
- -
|
29
|
+
version: '6'
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '4.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - ~>
|
37
|
+
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '1.7'
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ~>
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.7'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ~>
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '10.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - ~>
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '10.0'
|
61
61
|
description:
|
@@ -65,7 +65,7 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
|
-
- .gitignore
|
68
|
+
- ".gitignore"
|
69
69
|
- Gemfile
|
70
70
|
- LICENSE.txt
|
71
71
|
- README.md
|
@@ -83,19 +83,18 @@ require_paths:
|
|
83
83
|
- lib
|
84
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.5.1
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: A very simple ActiveRecord search pattern
|
100
100
|
test_files: []
|
101
|
-
has_rdoc:
|