jinrai 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a92fa21d25f7ac12d4a77d0ede116fb8712608c
4
- data.tar.gz: 776eeeed260c5a79bfdbef5007042a84696602bc
3
+ metadata.gz: f90cbb057b2d8ed397a95afbd1be11e53f9a12ee
4
+ data.tar.gz: 262d9de132390d3eb80e4641f38372950ac02967
5
5
  SHA512:
6
- metadata.gz: 0d92800fd47ee98b909ea62d3405835afb274ab0ee0a4ea4c88df8809397401963bbfdc254c1f97917e6fe1868478cf7d959d00e774378ef66b9868f679fa9d7
7
- data.tar.gz: 3afc42adc4c5ba2aad592df04e8f3082fa31ce1c49be6ba131c26e0cc4c8af15985c4eefac29a6f4b66ea3a9426cd75969d8f0101dd7e6383f43f44144652d18
6
+ metadata.gz: 2bce5e4bc9d332e8d3e3921296d624622dd347cfbfc402b426396c15704a207622e378fc4b31af93232f1e458f29f233f19e34a619d9ce394d649cdeacecb436
7
+ data.tar.gz: 0141f31333eef1a456fe15edec0feaa0b761fe3d32310d996072aaed5c80bfe7cf28c9f503ccd77db8b0c9b23b522a2ff2718a5ecde409e019aae58503a5345c
@@ -9,3 +9,6 @@ ActiveSupport.on_load :active_record do
9
9
  ActiveRecord::Relation.send(:prepend, Jinrai::ActiveRecord::Result)
10
10
  ActiveRecord::Base.send(:include, Jinrai::ActiveRecord::Core)
11
11
  end
12
+
13
+ module Jinrai
14
+ end
@@ -1,20 +1,22 @@
1
1
  require 'jinrai/active_record/finder_methods'
2
2
 
3
- module Jinrai::ActiveRecord
4
- module Core
5
- extend ActiveSupport::Concern
3
+ module Jinrai
4
+ module ActiveRecord
5
+ module Core
6
+ extend ActiveSupport::Concern
6
7
 
7
8
 
8
- module ClassMethods
9
- def inherited(kls)
10
- super
11
- kls.send(:include, Jinrai::ActiveRecord::FinderMethods) if kls.superclass == ::ActiveRecord::Base
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
- included do
16
- descendants.each do |kls|
17
- kls.send(:include, Jinrai::ActiveRecord::FinderMethods) if kls.superclass == ::ActiveRecord::Base
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::ActiveRecord
4
- module CursorMethods
5
- include Jinrai::ConfigurationMethods
3
+ module Jinrai
4
+ module ActiveRecord
5
+ module CursorMethods
6
+ include Jinrai::ConfigurationMethods
6
7
 
7
- def since_cursor
8
- encode_cursor(first)
9
- end
8
+ def since_cursor
9
+ encode_cursor(first)
10
+ end
10
11
 
11
- def till_cursor
12
- encode_cursor(last)
13
- end
12
+ def till_cursor
13
+ encode_cursor(last)
14
+ end
14
15
 
15
- def per(num = nil)
16
- num ||= default_cursor_per
17
- if (n = num.to_i).negative? || !(/^\d/ =~ num.to_s)
18
- self
19
- else
20
- self.is_cursored = true
21
- limit(n)
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
- private
26
+ private
26
27
 
27
- def encode_cursor(record)
28
- attributes = default_cursor_format.map do |attr|
29
- record.send(attr)
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::ActiveRecord #:nodoc:
4
- module FinderMethods
5
- extend ActiveSupport::Concern
3
+ module Jinrai
4
+ module ActiveRecord #:nodoc:
5
+ module FinderMethods
6
+ extend ActiveSupport::Concern
6
7
 
7
- included do
8
- include Jinrai::ConfigurationMethods
8
+ included do
9
+ include Jinrai::ConfigurationMethods
9
10
 
10
- def to_cursor
11
- cursor_format = self.class.default_cursor_format
12
- attributes = cursor_format.map do |attribute|
13
- self.send(attribute)
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
- module ClassMethods
20
+ module ClassMethods
20
21
 
21
- def cursor(**options)
22
- relation =
23
- if default_cursor_sort_order == :desc
24
- cursoring(:lt, :gt, options[:since], options[:sort_at]).cursoring(:gt, :lt, options[:till], options[:sort_at])
25
- elsif default_cursor_sort_order == :asc
26
- cursoring(:gt, :lt, options[:since], options[:sort_at]).cursoring(:lt, :gt, options[:till], options[:sort_at])
27
- end
28
- relation.extending_cursor
29
- end
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
- def after(cursor, **options)
32
- relation =
33
- if default_cursor_sort_order == :desc
34
- cursoring(:lt, :gt, cursor, options[:sort_at])
35
- elsif default_cursor_sort_order == :asc
36
- cursoring(:gt, :lt, cursor, options[:sort_at])
37
- end
38
- relation.extending_cursor
39
- end
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
- def before(cursor, **options)
42
- relation =
43
- if default_cursor_sort_order == :desc
44
- cursoring(:gt, :lt, cursor, options[:sort_at])
45
- elsif default_cursor_sort_order == :asc
46
- cursoring(:lt, :gt, cursor, options[:sort_at])
47
- end
48
- relation.extending_cursor
49
- end
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
- def extending_cursor
52
- extending { include Jinrai::ActiveRecord::CursorMethods }.per
53
- end
52
+ def extending_cursor
53
+ extending { include Jinrai::ActiveRecord::CursorMethods }.per
54
+ end
54
55
 
55
56
 
56
- def cursoring(rank, rank_for_primary, cursor, sort_at)
57
- sort_at ||= primary_key
58
- if cursor
59
- attributes = HashWithIndifferentAccess.new(decode_cursor(cursor))
60
- id = find_by(attributes).id
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
- if sort_at != primary_key
63
- condition_1 = arel_table[sort_at].send(rank, attributes[sort_at])
64
- condition_2 = arel_table.grouping(arel_table[sort_at].eq(attributes[sort_at]).and(arel_table[primary_key].send(rank_for_primary, id)))
65
- relation = where(condition_1.or(condition_2))
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 = where(arel_table[primary_key].send(rank, id))
71
+ relation = all
68
72
  end
69
- else
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
- private
76
+ private
76
77
 
77
- def decode_cursor(cursor)
78
- attributes = Base64.urlsafe_decode64(cursor).split("_")
79
- default_cursor_format.zip(attributes).to_h
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::ActiveRecord
2
- module Result
3
- attr_writer :is_cursored
1
+ module Jinrai
2
+ module ActiveRecord
3
+ module Result
4
+ attr_writer :is_cursored
4
5
 
5
- def initialize(*a)
6
- @is_cursored = false
7
- super(*a)
8
- end
6
+ def initialize(*a)
7
+ @is_cursored = false
8
+ super(*a)
9
+ end
9
10
 
10
- def cursored?
11
- @is_cursored
11
+ def cursored?
12
+ @is_cursored
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,3 @@
1
1
  module Jinrai
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
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.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-14 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails