yap 1.2.3 → 1.3.0
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 +9 -0
- data/lib/yap/filter.rb +24 -0
- data/lib/yap/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a8cb98d770164d8c28e7b5ecb574a7962430fe
|
4
|
+
data.tar.gz: 3841588ca088dc11673d04a8d2a9e7c8aa1705cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ac5778aace7e20671a21195db90c12d2672e2de0e9244d063a429b1334b6ffefbd7791c0cb50ca75f8eb38b78a582449bdc9368077eddfdd4fe5df902d7e71b
|
7
|
+
data.tar.gz: 170f73e6b59ef73478fe75745336a53f1f8fa188a8aa613ae638ad97d5eff4837ef754ad39a302dcdadca32ad9dd5c3e3a6a3a5f937a8d8489c46be300190e85
|
data/README.md
CHANGED
@@ -162,6 +162,15 @@ If an option cannot be parsed it will raise `Yap::PaginationError` or `Yap::Filt
|
|
162
162
|
|
163
163
|
## Changelog
|
164
164
|
|
165
|
+
### 1.3
|
166
|
+
|
167
|
+
* added comparison operators <, >, <=, >= to filters
|
168
|
+
* usage: ?filter[id]=>=100
|
169
|
+
* will give you any element with and id equal to or greater 100
|
170
|
+
* you can even combine multiple filters: ?filter[id]=>=100,<200
|
171
|
+
* although the same result can be achieved through ?filter[id]=100...200
|
172
|
+
* _currently, there is not support for strings and dates. This will be implemented in the future_
|
173
|
+
|
165
174
|
### 1.2
|
166
175
|
|
167
176
|
* added sorting by multiple elements
|
data/lib/yap/filter.rb
CHANGED
@@ -16,6 +16,8 @@ module Yap
|
|
16
16
|
end
|
17
17
|
|
18
18
|
case value
|
19
|
+
when /([<>]=?)(.+)/
|
20
|
+
match, value = handle_comparison_operators(match, column, $1.to_sym, $2)
|
19
21
|
when /(.+)\.{3}(.+)/
|
20
22
|
value = $1...$2
|
21
23
|
when /(.+)\.{2}(.+)/
|
@@ -31,5 +33,27 @@ module Yap
|
|
31
33
|
self[match][column] << value
|
32
34
|
end
|
33
35
|
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def handle_comparison_operators(match, column, operator, value)
|
40
|
+
# TODO make comparison operators work for String. See here: http://c4se.hatenablog.com/entry/2013/10/01/010305
|
41
|
+
value = Float(value) rescue raise(Yap::FilterError, 'You can only use float values with comparison operators <, >, <= and >=.')
|
42
|
+
|
43
|
+
case operator
|
44
|
+
when :<
|
45
|
+
handle_comparison_operators(toggle_match(match), column, :>=, value)
|
46
|
+
when :>
|
47
|
+
handle_comparison_operators(toggle_match(match), column, :<=, value)
|
48
|
+
when :<=
|
49
|
+
return match, -Float::INFINITY..value.to_f
|
50
|
+
when :>=
|
51
|
+
return match, value.to_f..Float::INFINITY
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def toggle_match(match)
|
56
|
+
match == :where ? :not : :where
|
57
|
+
end
|
34
58
|
end
|
35
59
|
end
|
data/lib/yap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Finn Glöe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.4.
|
77
|
+
rubygems_version: 2.4.8
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Yet another paginator for Ruby on Rails
|