jinrai 1.0.0 → 1.0.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/lib/jinrai.rb +3 -0
- data/lib/jinrai/active_record/core.rb +13 -11
- data/lib/jinrai/active_record/cursor_methods.rb +24 -22
- data/lib/jinrai/active_record/finder_methods.rb +62 -60
- data/lib/jinrai/active_record/result.rb +11 -9
- data/lib/jinrai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f90cbb057b2d8ed397a95afbd1be11e53f9a12ee
|
4
|
+
data.tar.gz: 262d9de132390d3eb80e4641f38372950ac02967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bce5e4bc9d332e8d3e3921296d624622dd347cfbfc402b426396c15704a207622e378fc4b31af93232f1e458f29f233f19e34a619d9ce394d649cdeacecb436
|
7
|
+
data.tar.gz: 0141f31333eef1a456fe15edec0feaa0b761fe3d32310d996072aaed5c80bfe7cf28c9f503ccd77db8b0c9b23b522a2ff2718a5ecde409e019aae58503a5345c
|
data/lib/jinrai.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
require 'jinrai/active_record/finder_methods'
|
2
2
|
|
3
|
-
module Jinrai
|
4
|
-
module
|
5
|
-
|
3
|
+
module Jinrai
|
4
|
+
module ActiveRecord
|
5
|
+
module Core
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
module ClassMethods
|
10
|
+
def inherited(kls)
|
11
|
+
super
|
12
|
+
kls.send(:include, Jinrai::ActiveRecord::FinderMethods) if kls.superclass == ::ActiveRecord::Base
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
included do
|
17
|
+
descendants.each do |kls|
|
18
|
+
kls.send(:include, Jinrai::ActiveRecord::FinderMethods) if kls.superclass == ::ActiveRecord::Base
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -1,34 +1,36 @@
|
|
1
1
|
require 'jinrai/config'
|
2
2
|
|
3
|
-
module Jinrai
|
4
|
-
module
|
5
|
-
|
3
|
+
module Jinrai
|
4
|
+
module ActiveRecord
|
5
|
+
module CursorMethods
|
6
|
+
include Jinrai::ConfigurationMethods
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def since_cursor
|
9
|
+
encode_cursor(first)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def till_cursor
|
13
|
+
encode_cursor(last)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def per(num = nil)
|
17
|
+
num ||= default_cursor_per
|
18
|
+
if (n = num.to_i).negative? || !(/^\d/ =~ num.to_s)
|
19
|
+
self
|
20
|
+
else
|
21
|
+
self.is_cursored = true
|
22
|
+
limit(n)
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
+
private
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def encode_cursor(record)
|
29
|
+
attributes = default_cursor_format.map do |attr|
|
30
|
+
record.send(attr)
|
31
|
+
end
|
32
|
+
Base64.urlsafe_encode64(attributes.join("_"))
|
30
33
|
end
|
31
|
-
Base64.urlsafe_encode64(attributes.join("_"))
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -1,82 +1,84 @@
|
|
1
1
|
require 'jinrai/active_record/cursor_methods'
|
2
2
|
|
3
|
-
module Jinrai
|
4
|
-
module
|
5
|
-
|
3
|
+
module Jinrai
|
4
|
+
module ActiveRecord #:nodoc:
|
5
|
+
module FinderMethods
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
included do
|
9
|
+
include Jinrai::ConfigurationMethods
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def to_cursor
|
12
|
+
cursor_format = self.class.default_cursor_format
|
13
|
+
attributes = cursor_format.map do |attribute|
|
14
|
+
self.send(attribute)
|
15
|
+
end
|
16
|
+
Base64.urlsafe_encode64(attributes.join("_"))
|
14
17
|
end
|
15
|
-
Base64.urlsafe_encode64(attributes.join("_"))
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
+
module ClassMethods
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
def cursor(**options)
|
23
|
+
relation =
|
24
|
+
if default_cursor_sort_order == :desc
|
25
|
+
cursoring(:lt, :gt, options[:since], options[:sort_at]).cursoring(:gt, :lt, options[:till], options[:sort_at])
|
26
|
+
elsif default_cursor_sort_order == :asc
|
27
|
+
cursoring(:gt, :lt, options[:since], options[:sort_at]).cursoring(:lt, :gt, options[:till], options[:sort_at])
|
28
|
+
end
|
29
|
+
relation.extending_cursor
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
def after(cursor, **options)
|
33
|
+
relation =
|
34
|
+
if default_cursor_sort_order == :desc
|
35
|
+
cursoring(:lt, :gt, cursor, options[:sort_at])
|
36
|
+
elsif default_cursor_sort_order == :asc
|
37
|
+
cursoring(:gt, :lt, cursor, options[:sort_at])
|
38
|
+
end
|
39
|
+
relation.extending_cursor
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
def before(cursor, **options)
|
43
|
+
relation =
|
44
|
+
if default_cursor_sort_order == :desc
|
45
|
+
cursoring(:gt, :lt, cursor, options[:sort_at])
|
46
|
+
elsif default_cursor_sort_order == :asc
|
47
|
+
cursoring(:lt, :gt, cursor, options[:sort_at])
|
48
|
+
end
|
49
|
+
relation.extending_cursor
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def extending_cursor
|
53
|
+
extending { include Jinrai::ActiveRecord::CursorMethods }.per
|
54
|
+
end
|
54
55
|
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
def cursoring(rank, rank_for_primary, cursor, sort_at)
|
58
|
+
sort_at ||= primary_key
|
59
|
+
if cursor
|
60
|
+
attributes = HashWithIndifferentAccess.new(decode_cursor(cursor))
|
61
|
+
id = find_by(attributes).id
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
if sort_at != primary_key
|
64
|
+
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, id)))
|
66
|
+
relation = where(condition_1.or(condition_2))
|
67
|
+
else
|
68
|
+
relation = where(arel_table[primary_key].send(rank, id))
|
69
|
+
end
|
66
70
|
else
|
67
|
-
relation =
|
71
|
+
relation = all
|
68
72
|
end
|
69
|
-
|
70
|
-
relation = all
|
73
|
+
relation.order(sort_at => default_cursor_sort_order)
|
71
74
|
end
|
72
|
-
relation.order(sort_at => default_cursor_sort_order)
|
73
|
-
end
|
74
75
|
|
75
|
-
|
76
|
+
private
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
def decode_cursor(cursor)
|
79
|
+
attributes = Base64.urlsafe_decode64(cursor).split("_")
|
80
|
+
default_cursor_format.zip(attributes).to_h
|
81
|
+
end
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
-
module Jinrai
|
2
|
-
module
|
3
|
-
|
1
|
+
module Jinrai
|
2
|
+
module ActiveRecord
|
3
|
+
module Result
|
4
|
+
attr_writer :is_cursored
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(*a)
|
7
|
+
@is_cursored = false
|
8
|
+
super(*a)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def cursored?
|
12
|
+
@is_cursored
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
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.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- atomiyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|