jinrai 1.0.1 → 1.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b26a6b9d12517eed97e97a11bb4550dad6cf03ab8712b3b56d3d40709cd2f5c
|
4
|
+
data.tar.gz: f13582e01a09ba49fe3e945b4f9f213537fcc8c9da6182669cc75215c7b2121d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d044081459021b3352961f6aad68ae61c525ec57c512867327ae13011165224fdf8de8d1edc03371778f91f322baa196f38a2bccb5f8c0e6b72b2c3ec5943529
|
7
|
+
data.tar.gz: 44a3f8de879cab29dcded927d7202f247e66e56f1d8d36e33430c951292be19dfb43d27c029ce3ff37532f5d902dc548282b24c35c77907a43871e5880ea97ca
|
@@ -27,7 +27,8 @@ module Jinrai
|
|
27
27
|
|
28
28
|
def encode_cursor(record)
|
29
29
|
attributes = default_cursor_format.map do |attr|
|
30
|
-
record.send(attr)
|
30
|
+
value = record.send(attr)
|
31
|
+
value.respond_to?(:iso8601) ? value.iso8601 : value
|
31
32
|
end
|
32
33
|
Base64.urlsafe_encode64(attributes.join("_"))
|
33
34
|
end
|
@@ -9,9 +9,9 @@ module Jinrai
|
|
9
9
|
include Jinrai::ConfigurationMethods
|
10
10
|
|
11
11
|
def to_cursor
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
attributes = self.class.default_cursor_format.map do |attr|
|
13
|
+
value = send(attr)
|
14
|
+
value.respond_to?(:iso8601) ? value.iso8601 : value
|
15
15
|
end
|
16
16
|
Base64.urlsafe_encode64(attributes.join("_"))
|
17
17
|
end
|
@@ -57,12 +57,11 @@ module Jinrai
|
|
57
57
|
def cursoring(rank, rank_for_primary, cursor, sort_at)
|
58
58
|
sort_at ||= primary_key
|
59
59
|
if cursor
|
60
|
-
attributes = HashWithIndifferentAccess.new(decode_cursor(cursor))
|
61
|
-
id = find_by(attributes).id
|
60
|
+
attributes = HashWithIndifferentAccess.new(default_attributes_from_cursor.call(decode_cursor(cursor)))
|
62
61
|
|
63
62
|
if sort_at != primary_key
|
64
63
|
condition_1 = arel_table[sort_at].send(rank, attributes[sort_at])
|
65
|
-
condition_2 = arel_table.grouping(arel_table[sort_at].eq(attributes[sort_at]).and(arel_table[primary_key].send(rank_for_primary,
|
64
|
+
condition_2 = arel_table.grouping(arel_table[sort_at].eq(attributes[sort_at]).and(arel_table[primary_key].send(rank_for_primary, attributes[primary_key])))
|
66
65
|
relation = where(condition_1.or(condition_2))
|
67
66
|
else
|
68
67
|
relation = where(arel_table[primary_key].send(rank, id))
|
data/lib/jinrai/config.rb
CHANGED
@@ -14,12 +14,14 @@ module Jinrai #:nodoc:
|
|
14
14
|
class Config #:nodoc:
|
15
15
|
attr_accessor :default_cursor_per,
|
16
16
|
:default_cursor_format,
|
17
|
-
:default_cursor_sort_order
|
17
|
+
:default_cursor_sort_order,
|
18
|
+
:default_attributes_from_cursor
|
18
19
|
|
19
20
|
def initialize
|
20
21
|
@default_cursor_per = 20
|
21
22
|
@default_cursor_format = %i[created_at id]
|
22
23
|
@default_cursor_sort_order = :desc
|
24
|
+
@default_attributes_from_cursor = Proc.new { |decoded_cursor| decoded_cursor }
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -16,6 +16,11 @@ module Jinrai #:nodoc:
|
|
16
16
|
@_default_cursor_sort_order = rank.to_sym
|
17
17
|
end
|
18
18
|
|
19
|
+
def attributes_from_cursor(&block)
|
20
|
+
@_default_attributes_from_cursor = block
|
21
|
+
|
22
|
+
end
|
23
|
+
|
19
24
|
def default_cursor_per
|
20
25
|
@_default_cursor_per || Jinrai.config.default_cursor_per
|
21
26
|
end
|
@@ -27,6 +32,10 @@ module Jinrai #:nodoc:
|
|
27
32
|
def default_cursor_sort_order
|
28
33
|
@_default_cursor_sort_order || Jinrai.config.default_cursor_sort_order
|
29
34
|
end
|
35
|
+
|
36
|
+
def default_attributes_from_cursor
|
37
|
+
@_default_attributes_from_cursor || Jinrai.config.default_attributes_from_cursor
|
38
|
+
end
|
30
39
|
end
|
31
40
|
end
|
32
41
|
end
|
data/lib/jinrai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jinrai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- atomiyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Jinrai is a awesome Cursor
|
69
|
+
description: Jinrai is a awesome Cursor based pagination Link.
|
70
70
|
email:
|
71
71
|
- akifumi.tomiyama@studyplus.jp
|
72
72
|
executables: []
|
@@ -103,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.6.13
|
106
|
+
rubygems_version: 3.0.2
|
108
107
|
signing_key:
|
109
108
|
specification_version: 4
|
110
|
-
summary: A cursor
|
109
|
+
summary: A cursor based pagination plugin for Rails
|
111
110
|
test_files: []
|