yap 1.3.0 → 1.4.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 +5 -1
- data/lib/string_infinity.rb +14 -0
- data/lib/yap.rb +1 -0
- data/lib/yap/extended_range.rb +25 -0
- data/lib/yap/filter.rb +4 -5
- data/lib/yap/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90a7fb8f804bd7b631c632deeb7241bfcdac00ee
|
4
|
+
data.tar.gz: 4d2de49002fcdc9d79dd60786a3c191fac6275cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1669e8d881f42da049c61c49c1b1c483340ece46642f281831dd104f999198320eca72b82c097d8d1df534830b8c97223a559c080fdae695671c8f9a9a36a89e
|
7
|
+
data.tar.gz: fac27392172ca4fbbf5fb96332f79bcf157893a87076335e094d50908589b9e85e6f1ee5cbaa55d900538bf688cbc7451751d985ec57af61a7e32af9db2d564e
|
data/README.md
CHANGED
@@ -162,6 +162,10 @@ If an option cannot be parsed it will raise `Yap::PaginationError` or `Yap::Filt
|
|
162
162
|
|
163
163
|
## Changelog
|
164
164
|
|
165
|
+
### 1.4
|
166
|
+
|
167
|
+
* added support for strings and dates with comparison parameters
|
168
|
+
|
165
169
|
### 1.3
|
166
170
|
|
167
171
|
* added comparison operators <, >, <=, >= to filters
|
@@ -169,7 +173,7 @@ If an option cannot be parsed it will raise `Yap::PaginationError` or `Yap::Filt
|
|
169
173
|
* will give you any element with and id equal to or greater 100
|
170
174
|
* you can even combine multiple filters: ?filter[id]=>=100,<200
|
171
175
|
* although the same result can be achieved through ?filter[id]=100...200
|
172
|
-
* _currently, there is
|
176
|
+
* ~~_currently, there is no support for strings and dates. This will be implemented in the future._~~ (see version 1.4)
|
173
177
|
|
174
178
|
### 1.2
|
175
179
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class StringInfinity < String
|
2
|
+
def -@
|
3
|
+
String::INFINITY_NEGATIVE
|
4
|
+
end
|
5
|
+
|
6
|
+
def ==(value)
|
7
|
+
self.class == value.class
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class StringInfinityNegative < StringInfinity; end
|
12
|
+
|
13
|
+
String::INFINITY = StringInfinity.new
|
14
|
+
String::INFINITY_NEGATIVE = StringInfinityNegative.new
|
data/lib/yap.rb
CHANGED
@@ -3,6 +3,7 @@ require 'yap/active_record/relation'
|
|
3
3
|
require 'yap/column_mapper'
|
4
4
|
require 'yap/filterable'
|
5
5
|
require 'yap/exceptions'
|
6
|
+
require 'string_infinity'
|
6
7
|
|
7
8
|
##
|
8
9
|
# Support for Active Record pagination. All options can be safely accessed by the user through url query parameters. To
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Yap
|
2
|
+
class ExtendedRange < Range
|
3
|
+
def begin
|
4
|
+
infinity_or_do_not_change super
|
5
|
+
end
|
6
|
+
|
7
|
+
def end
|
8
|
+
infinity_or_do_not_change super
|
9
|
+
end
|
10
|
+
|
11
|
+
def infinity_or_do_not_change(value)
|
12
|
+
if value.is_a? StringInfinity
|
13
|
+
if value == String::INFINITY
|
14
|
+
Float::INFINITY
|
15
|
+
elsif value == -String::INFINITY
|
16
|
+
-Float::INFINITY
|
17
|
+
else
|
18
|
+
raise ArgumentError, "Invalid value for StringInfinity."
|
19
|
+
end
|
20
|
+
else
|
21
|
+
value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/yap/filter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yap/extended_range'
|
2
|
+
|
1
3
|
module Yap
|
2
4
|
class Filter < Hash
|
3
5
|
def initialize
|
@@ -37,18 +39,15 @@ module Yap
|
|
37
39
|
private
|
38
40
|
|
39
41
|
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
42
|
case operator
|
44
43
|
when :<
|
45
44
|
handle_comparison_operators(toggle_match(match), column, :>=, value)
|
46
45
|
when :>
|
47
46
|
handle_comparison_operators(toggle_match(match), column, :<=, value)
|
48
47
|
when :<=
|
49
|
-
return match, -
|
48
|
+
return match, ExtendedRange.new(-String::INFINITY, value)
|
50
49
|
when :>=
|
51
|
-
return match, value
|
50
|
+
return match, ExtendedRange.new(value, String::INFINITY)
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
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.4.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:
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -47,10 +47,12 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- LICENSE
|
49
49
|
- README.md
|
50
|
+
- lib/string_infinity.rb
|
50
51
|
- lib/yap.rb
|
51
52
|
- lib/yap/active_record/relation.rb
|
52
53
|
- lib/yap/column_mapper.rb
|
53
54
|
- lib/yap/exceptions.rb
|
55
|
+
- lib/yap/extended_range.rb
|
54
56
|
- lib/yap/filter.rb
|
55
57
|
- lib/yap/filterable.rb
|
56
58
|
- lib/yap/version.rb
|
@@ -74,8 +76,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
76
|
version: '0'
|
75
77
|
requirements: []
|
76
78
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.5.1
|
78
80
|
signing_key:
|
79
81
|
specification_version: 4
|
80
82
|
summary: Yet another paginator for Ruby on Rails
|
81
83
|
test_files: []
|
84
|
+
has_rdoc:
|