bolter 0.2.2 → 0.3.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 +4 -3
- data/lib/bolter/railtie.rb +0 -12
- data/lib/bolter/searchable.rb +3 -18
- data/lib/bolter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52578fcf1c9bc72f05c801f76bc2ca6ac39f4770
|
4
|
+
data.tar.gz: fb776fdcc9b125db0b42977011a24df11d7b6d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f62de8aa336b4298e03738330dcae5b52ea0635ead54d1e59d4c88c22de9423c6f598e4bd02c6469457a88a20d8952971095d559258c0fbf31a154daaf1272c
|
7
|
+
data.tar.gz: 929f9fa946426da756cd52f78b827ae2ad9645ac8a5d5df62e8f77da83ee727b283fe2bc443f3eb0384e5d99b48cab5ba083c99648585a386ed5cad617c3ef91
|
data/README.md
CHANGED
@@ -25,7 +25,10 @@ Or install it yourself as:
|
|
25
25
|
Model:
|
26
26
|
```ruby
|
27
27
|
class Book < ActiveRecord::Base
|
28
|
-
|
28
|
+
include Bolter::Searchable
|
29
|
+
include Bolter::Sortable
|
30
|
+
|
31
|
+
scope :with_author, -> (author) {
|
29
32
|
self.where("author like ?",author)
|
30
33
|
}
|
31
34
|
end
|
@@ -52,8 +55,6 @@ Controller:
|
|
52
55
|
@books = Book.search(params[:filters]).sorting(params[:sorting])
|
53
56
|
```
|
54
57
|
|
55
|
-
|
56
|
-
|
57
58
|
## Development
|
58
59
|
|
59
60
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/bolter/railtie.rb
CHANGED
@@ -10,18 +10,6 @@ module Bolter
|
|
10
10
|
ActionView::Base.send :include, Bolter::FormHelper
|
11
11
|
ActionView::Base.send :include, Bolter::SortHelper
|
12
12
|
end
|
13
|
-
|
14
|
-
ActiveSupport.on_load(:active_record) do
|
15
|
-
ActiveRecord::Base.send :include, Bolter::Searchable
|
16
|
-
ActiveRecord::Base.send :include, Bolter::Sortable
|
17
|
-
end
|
18
|
-
|
19
|
-
if defined? ::Mongoid::Document
|
20
|
-
ActiveSupport.on_load(:mongoid) do
|
21
|
-
Mongoid::Document.send :include, Bolter::Searchable
|
22
|
-
Mongoid::Document.send :include, Bolter::Sortable
|
23
|
-
end
|
24
|
-
end
|
25
13
|
end
|
26
14
|
end
|
27
15
|
end
|
data/lib/bolter/searchable.rb
CHANGED
@@ -2,29 +2,14 @@ module Bolter
|
|
2
2
|
module Searchable
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
included do
|
5
|
-
cattr_reader :
|
6
|
-
|
7
|
-
class_methods do
|
8
|
-
def filter(name, value, &block)
|
9
|
-
@@filters ||= []
|
10
|
-
@@filters << name.to_s
|
11
|
-
scope name.to_sym, value, &block
|
12
|
-
end
|
13
|
-
def search(params = {}, options = {})
|
14
|
-
# Prepare filters
|
15
|
-
enabled_filters = Array(options[:filters] || self.filters).map(&:to_s)
|
16
|
-
|
17
|
-
# Prepare default result
|
5
|
+
cattr_reader :used_as_filters
|
6
|
+
def self.search(params = {}, options = {})
|
18
7
|
result = self
|
19
|
-
|
20
8
|
# Prepare params to search
|
21
9
|
search = (params || {}).clone.reject{|_,value| value.to_s.empty? }
|
22
|
-
|
23
10
|
# Apply filters
|
24
11
|
search.each do |name, value|
|
25
|
-
if
|
26
|
-
result = result.send(name.to_s, value)
|
27
|
-
end
|
12
|
+
result = result.send(name.to_s, value) if result.respond_to? name.to_s
|
28
13
|
end
|
29
14
|
result
|
30
15
|
end
|
data/lib/bolter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bolter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Shurmin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|