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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f077be5f7527087f34a2b3904fc1ef41892ac5e
4
- data.tar.gz: e87af41c1e3c37ec7476cbf0c35a3db81f4bd61f
3
+ metadata.gz: 52578fcf1c9bc72f05c801f76bc2ca6ac39f4770
4
+ data.tar.gz: fb776fdcc9b125db0b42977011a24df11d7b6d1e
5
5
  SHA512:
6
- metadata.gz: 972bb1adec38bcff8f0bb16712ec0af16f167a66fc50af9e2c2897608ce4d4ccb47489ff27f2ecb3793a68ac2ca204967d48d0b4f08d08cee55a075cc41dfe51
7
- data.tar.gz: cb4fea07d44051b56f52d5e4904fb725f71e39e82ce1ff2c1fcb2c46a938b8c068beb44499a33284ce1c90e4c3ecfc97c0553470e39f7adaf35ef34d62106f01
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
- filter :with_author, -> (author) {
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.
@@ -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
@@ -2,29 +2,14 @@ module Bolter
2
2
  module Searchable
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
- cattr_reader :filters
6
- end
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 enabled_filters.include?(name.to_s)
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
@@ -1,3 +1,3 @@
1
1
  module Bolter
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.2
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-06 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler