bolter 0.1.0 → 0.1.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 +2 -2
- data/lib/bolter/searchable.rb +9 -14
- data/lib/bolter/sortable.rb +4 -4
- data/lib/bolter/version.rb +1 -1
- metadata +3 -4
- data/bin/console +0 -14
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec99ab0f4a566eef9a9aaba790dd683cf37cb95b
|
4
|
+
data.tar.gz: e6de1200f625cd5a8427158cca89ed5556a0aab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2c784b730edb31276812828518889f92eda958ad58027e4b15f83689ca3dd1eae36bf68db48d56c3e70893fc00dbe84c1141f297a80b4ba507bb25d67dba65d
|
7
|
+
data.tar.gz: 815bdc59eadb6cc3fac23f8061d425914c2b60f772e4406e7fbdb2aec521a6c5191210c0fd64fb36c87b405ecc87f5f48618173f67c81872aebe0dc25c3bd52b
|
data/README.md
CHANGED
@@ -36,8 +36,8 @@ View:
|
|
36
36
|
.search
|
37
37
|
= form_tag books_path, method: :get, id: :search do
|
38
38
|
= fields_for :filters, OpenStruct.new(params[:filters]) do |f|
|
39
|
-
= f.label :with_name,
|
40
|
-
= f.text_field :with_name
|
39
|
+
= f.label :with_name, Book.human_attribute_name(:name)
|
40
|
+
= f.text_field :with_name
|
41
41
|
.index
|
42
42
|
%table
|
43
43
|
%tr
|
data/lib/bolter/searchable.rb
CHANGED
@@ -3,37 +3,32 @@ module Bolter
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
included do
|
5
5
|
cattr_reader :filters
|
6
|
-
|
6
|
+
end
|
7
|
+
class_methods do
|
8
|
+
def filter(name, value, &block)
|
7
9
|
@@filters ||= []
|
8
10
|
@@filters << name.to_s
|
9
11
|
scope name.to_sym, value, &block
|
10
12
|
end
|
11
|
-
|
12
|
-
def self.search(params = {}, options = {})
|
13
|
+
def search(params = {}, options = {})
|
13
14
|
# Prepare filters
|
14
|
-
|
15
|
+
enabled_filters = Array(options[:filters] || self.filters).map(&:to_s)
|
15
16
|
|
16
17
|
# Prepare default result
|
17
|
-
result = self
|
18
|
+
result = self
|
18
19
|
|
19
20
|
# Prepare params to search
|
20
21
|
search = (params || {}).clone.reject{|_,value| value.to_s.empty? }
|
21
22
|
|
22
23
|
# Apply filters
|
23
24
|
search.each do |name, value|
|
24
|
-
if
|
25
|
-
|
26
|
-
result = self.scopes[name.to_sym][:scope].arity == 0 ? result.send(name) : result.send(name, *value)
|
27
|
-
else
|
28
|
-
logger.warn "Skip filter #{self}.#{name}(#{value.inspect})"
|
29
|
-
end
|
25
|
+
if enabled_filters.include?(name.to_s)
|
26
|
+
result = result.send(name.to_s, value)
|
30
27
|
else
|
31
28
|
logger.warn "Unknown filter #{self}.#{name}(#{value.inspect})"
|
32
29
|
end
|
33
30
|
end
|
34
|
-
|
35
|
-
# return scope with applied filters
|
36
|
-
return result
|
31
|
+
result
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
data/lib/bolter/sortable.rb
CHANGED
@@ -2,15 +2,15 @@ module Bolter
|
|
2
2
|
module Sortable
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
included do
|
5
|
-
def self.sorting(sorting)
|
6
|
-
return self
|
5
|
+
def self.sorting(sorting = nil)
|
6
|
+
return self unless sorting
|
7
7
|
field, direction = sorting.split(':',2)
|
8
8
|
if self.attribute_names.include? field.to_s
|
9
9
|
if %W[asc desc].include? direction
|
10
|
-
self.
|
10
|
+
return self.order(Hash[field, direction])
|
11
11
|
end
|
12
12
|
else
|
13
|
-
self
|
13
|
+
self
|
14
14
|
end
|
15
15
|
end
|
16
16
|
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.1.
|
4
|
+
version: 0.1.1
|
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-04-
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,8 +93,6 @@ files:
|
|
93
93
|
- LICENSE.txt
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
|
-
- bin/console
|
97
|
-
- bin/setup
|
98
96
|
- bolter.gemspec
|
99
97
|
- lib/bolter.rb
|
100
98
|
- lib/bolter/helpers.rb
|
@@ -127,3 +125,4 @@ signing_key:
|
|
127
125
|
specification_version: 4
|
128
126
|
summary: This gem include sorting and filtering methods
|
129
127
|
test_files: []
|
128
|
+
has_rdoc:
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "bolter"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|