by_star 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/mysql.yml +92 -92
- data/.github/workflows/postgresql.yml +99 -99
- data/.gitignore +6 -6
- data/.travis.yml +92 -92
- data/CHANGELOG.md +63 -59
- data/Gemfile +18 -18
- data/MIT-LICENSE +20 -20
- data/README.md +616 -616
- data/Rakefile +18 -18
- data/UPGRADING +4 -4
- data/by_star.gemspec +34 -34
- data/cleaner.rb +24 -24
- data/lib/by_star/base.rb +69 -69
- data/lib/by_star/between.rb +185 -185
- data/lib/by_star/directional.rb +35 -35
- data/lib/by_star/kernel/date.rb +41 -41
- data/lib/by_star/kernel/in_time_zone.rb +20 -20
- data/lib/by_star/kernel/time.rb +41 -41
- data/lib/by_star/normalization.rb +156 -156
- data/lib/by_star/orm/active_record/by_star.rb +75 -75
- data/lib/by_star/orm/mongoid/by_star.rb +90 -90
- data/lib/by_star/orm/mongoid/reorder.rb +23 -23
- data/lib/by_star/version.rb +3 -3
- data/lib/by_star.rb +18 -18
- data/spec/database.yml +15 -15
- data/spec/fixtures/active_record/models.rb +12 -12
- data/spec/fixtures/active_record/schema.rb +19 -19
- data/spec/fixtures/mongoid/models.rb +31 -31
- data/spec/fixtures/shared/seeds.rb +36 -36
- data/spec/gemfiles/Gemfile.rails +5 -5
- data/spec/gemfiles/Gemfile.rails32 +7 -7
- data/spec/gemfiles/Gemfile.rails40 +7 -7
- data/spec/gemfiles/Gemfile.rails41 +7 -7
- data/spec/gemfiles/Gemfile.rails42 +7 -7
- data/spec/gemfiles/Gemfile.rails50 +7 -7
- data/spec/gemfiles/Gemfile.rails51 +7 -7
- data/spec/gemfiles/Gemfile.rails52 +7 -7
- data/spec/gemfiles/Gemfile.rails60 +7 -7
- data/spec/gemfiles/Gemfile.rails61 +7 -7
- data/spec/integration/active_record/active_record_spec.rb +41 -41
- data/spec/integration/mongoid/mongoid_spec.rb +39 -39
- data/spec/integration/shared/at_time.rb +53 -53
- data/spec/integration/shared/between_dates.rb +99 -99
- data/spec/integration/shared/between_times.rb +99 -99
- data/spec/integration/shared/by_calendar_month.rb +55 -55
- data/spec/integration/shared/by_cweek.rb +54 -54
- data/spec/integration/shared/by_day.rb +120 -120
- data/spec/integration/shared/by_direction.rb +126 -126
- data/spec/integration/shared/by_fortnight.rb +48 -48
- data/spec/integration/shared/by_month.rb +50 -50
- data/spec/integration/shared/by_quarter.rb +49 -49
- data/spec/integration/shared/by_week.rb +54 -54
- data/spec/integration/shared/by_weekend.rb +49 -49
- data/spec/integration/shared/by_year.rb +48 -48
- data/spec/integration/shared/index_scope_parameter.rb +111 -111
- data/spec/integration/shared/offset_parameter.rb +32 -32
- data/spec/integration/shared/order_parameter.rb +36 -36
- data/spec/integration/shared/relative.rb +174 -174
- data/spec/spec_helper.rb +33 -33
- data/spec/unit/kernel_date_spec.rb +113 -113
- data/spec/unit/kernel_time_spec.rb +57 -57
- data/spec/unit/normalization_spec.rb +384 -384
- data/tmp/.gitignore +1 -1
- metadata +3 -3
@@ -1,75 +1,75 @@
|
|
1
|
-
module ByStar
|
2
|
-
module ActiveRecord
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
module ClassMethods
|
6
|
-
include ::ByStar::Base
|
7
|
-
|
8
|
-
protected
|
9
|
-
|
10
|
-
def by_star_default_field
|
11
|
-
"#{self.table_name}.created_at"
|
12
|
-
end
|
13
|
-
|
14
|
-
def by_star_point_query(scope, field, start_time, end_time)
|
15
|
-
scope.where("#{field} >= ? AND #{field} <= ?", start_time, end_time)
|
16
|
-
end
|
17
|
-
|
18
|
-
def by_star_span_strict_query(scope, start_field, end_field, start_time, end_time)
|
19
|
-
scope.where("#{start_field} >= ? AND #{start_field} <= ? AND #{end_field} >= ? AND #{end_field} <= ?", start_time, end_time, start_time, end_time)
|
20
|
-
end
|
21
|
-
|
22
|
-
def by_star_span_loose_query(scope, start_field, end_field, start_time, end_time, options)
|
23
|
-
index_scope = by_star_eval_index_scope(start_time, end_time, options)
|
24
|
-
scope = scope.where("#{end_field} > ? AND #{start_field} < ?", start_time, end_time)
|
25
|
-
scope = scope.where("#{start_field} >= ?", index_scope) if index_scope
|
26
|
-
scope
|
27
|
-
end
|
28
|
-
|
29
|
-
def by_star_point_overlap_query(scope, field, time)
|
30
|
-
scope.where("#{field} = ?", time)
|
31
|
-
end
|
32
|
-
|
33
|
-
def by_star_span_overlap_query(scope, start_field, end_field, time, options)
|
34
|
-
index_scope = by_star_eval_index_scope(time, time, options)
|
35
|
-
scope = scope.where("#{end_field} > ? AND #{start_field} <= ?", time, time)
|
36
|
-
scope = scope.where("#{start_field} >= ?", index_scope) if index_scope
|
37
|
-
scope
|
38
|
-
end
|
39
|
-
|
40
|
-
def by_star_before_query(scope, field, time)
|
41
|
-
scope.where("#{field} <= ?", time)
|
42
|
-
end
|
43
|
-
|
44
|
-
def by_star_after_query(scope, field, time)
|
45
|
-
scope.where("#{field} >= ?", time)
|
46
|
-
end
|
47
|
-
|
48
|
-
def by_star_order(scope, order)
|
49
|
-
scope.order(order)
|
50
|
-
end
|
51
|
-
|
52
|
-
def oldest_query(options={})
|
53
|
-
field = by_star_start_field(options)
|
54
|
-
reorder("#{field} ASC").first
|
55
|
-
end
|
56
|
-
|
57
|
-
def newest_query(options={})
|
58
|
-
field = by_star_start_field(options)
|
59
|
-
reorder("#{field} DESC").first
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def previous(options={})
|
64
|
-
field = self.class.by_star_start_field(options)
|
65
|
-
value = self.send(field.split(".").last)
|
66
|
-
self.class.where("#{field} < ?", value).reorder("#{field} DESC").first
|
67
|
-
end
|
68
|
-
|
69
|
-
def next(options={})
|
70
|
-
field = self.class.by_star_start_field(options)
|
71
|
-
value = self.send(field.split(".").last)
|
72
|
-
self.class.where("#{field} > ?", value).reorder("#{field} ASC").first
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
1
|
+
module ByStar
|
2
|
+
module ActiveRecord
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
include ::ByStar::Base
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def by_star_default_field
|
11
|
+
"#{self.table_name}.created_at"
|
12
|
+
end
|
13
|
+
|
14
|
+
def by_star_point_query(scope, field, start_time, end_time)
|
15
|
+
scope.where("#{field} >= ? AND #{field} <= ?", start_time, end_time)
|
16
|
+
end
|
17
|
+
|
18
|
+
def by_star_span_strict_query(scope, start_field, end_field, start_time, end_time)
|
19
|
+
scope.where("#{start_field} >= ? AND #{start_field} <= ? AND #{end_field} >= ? AND #{end_field} <= ?", start_time, end_time, start_time, end_time)
|
20
|
+
end
|
21
|
+
|
22
|
+
def by_star_span_loose_query(scope, start_field, end_field, start_time, end_time, options)
|
23
|
+
index_scope = by_star_eval_index_scope(start_time, end_time, options)
|
24
|
+
scope = scope.where("#{end_field} > ? AND #{start_field} < ?", start_time, end_time)
|
25
|
+
scope = scope.where("#{start_field} >= ?", index_scope) if index_scope
|
26
|
+
scope
|
27
|
+
end
|
28
|
+
|
29
|
+
def by_star_point_overlap_query(scope, field, time)
|
30
|
+
scope.where("#{field} = ?", time)
|
31
|
+
end
|
32
|
+
|
33
|
+
def by_star_span_overlap_query(scope, start_field, end_field, time, options)
|
34
|
+
index_scope = by_star_eval_index_scope(time, time, options)
|
35
|
+
scope = scope.where("#{end_field} > ? AND #{start_field} <= ?", time, time)
|
36
|
+
scope = scope.where("#{start_field} >= ?", index_scope) if index_scope
|
37
|
+
scope
|
38
|
+
end
|
39
|
+
|
40
|
+
def by_star_before_query(scope, field, time)
|
41
|
+
scope.where("#{field} <= ?", time)
|
42
|
+
end
|
43
|
+
|
44
|
+
def by_star_after_query(scope, field, time)
|
45
|
+
scope.where("#{field} >= ?", time)
|
46
|
+
end
|
47
|
+
|
48
|
+
def by_star_order(scope, order)
|
49
|
+
scope.order(order)
|
50
|
+
end
|
51
|
+
|
52
|
+
def oldest_query(options={})
|
53
|
+
field = by_star_start_field(options)
|
54
|
+
reorder("#{field} ASC").first
|
55
|
+
end
|
56
|
+
|
57
|
+
def newest_query(options={})
|
58
|
+
field = by_star_start_field(options)
|
59
|
+
reorder("#{field} DESC").first
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def previous(options={})
|
64
|
+
field = self.class.by_star_start_field(options)
|
65
|
+
value = self.send(field.split(".").last)
|
66
|
+
self.class.where("#{field} < ?", value).reorder("#{field} DESC").first
|
67
|
+
end
|
68
|
+
|
69
|
+
def next(options={})
|
70
|
+
field = self.class.by_star_start_field(options)
|
71
|
+
value = self.send(field.split(".").last)
|
72
|
+
self.class.where("#{field} > ?", value).reorder("#{field} ASC").first
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,90 +1,90 @@
|
|
1
|
-
# In keeping with Mongoid standards, this module must be included into your model class, i.e.
|
2
|
-
#
|
3
|
-
# include Mongoid::ByStar
|
4
|
-
#
|
5
|
-
module Mongoid
|
6
|
-
module ByStar
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
include ::ByStar::Base
|
11
|
-
|
12
|
-
alias_method :original_by_star_end_field, :by_star_end_field
|
13
|
-
alias_method :original_by_star_start_field, :by_star_start_field
|
14
|
-
|
15
|
-
def by_star_end_field(options = {})
|
16
|
-
database_field_name original_by_star_end_field(options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def by_star_start_field(options = {})
|
20
|
-
database_field_name original_by_star_start_field(options)
|
21
|
-
end
|
22
|
-
|
23
|
-
def by_star_default_field
|
24
|
-
:created_at
|
25
|
-
end
|
26
|
-
|
27
|
-
protected
|
28
|
-
|
29
|
-
def by_star_point_query(scope, field, start_time, end_time)
|
30
|
-
range = start_time..end_time
|
31
|
-
scope.where(field => range)
|
32
|
-
end
|
33
|
-
|
34
|
-
def by_star_span_strict_query(scope, start_field, end_field, start_time, end_time)
|
35
|
-
range = start_time..end_time
|
36
|
-
scope.where(start_field => range).where(end_field => range)
|
37
|
-
end
|
38
|
-
|
39
|
-
def by_star_span_loose_query(scope, start_field, end_field, start_time, end_time, options)
|
40
|
-
index_scope = by_star_eval_index_scope(start_time, end_time, options)
|
41
|
-
scope = scope.gt(end_field => start_time).lt(start_field => end_time)
|
42
|
-
scope = scope.gte(start_field => index_scope) if index_scope
|
43
|
-
scope
|
44
|
-
end
|
45
|
-
|
46
|
-
def by_star_point_overlap_query(scope, field, time)
|
47
|
-
scope.where(field => time)
|
48
|
-
end
|
49
|
-
|
50
|
-
def by_star_span_overlap_query(scope, start_field, end_field, time, options)
|
51
|
-
index_scope = by_star_eval_index_scope(time, time, options)
|
52
|
-
scope = scope.gt(end_field => time).lte(start_field => time)
|
53
|
-
scope = scope.gte(start_field => index_scope) if index_scope
|
54
|
-
scope
|
55
|
-
end
|
56
|
-
|
57
|
-
def by_star_before_query(scope, field, time)
|
58
|
-
scope.lte(field => time)
|
59
|
-
end
|
60
|
-
|
61
|
-
def by_star_after_query(scope, field, time)
|
62
|
-
scope.gte(field => time)
|
63
|
-
end
|
64
|
-
|
65
|
-
def by_star_order(scope, order)
|
66
|
-
scope.order_by(order)
|
67
|
-
end
|
68
|
-
|
69
|
-
def oldest_query(options={})
|
70
|
-
field = by_star_start_field(options)
|
71
|
-
all.reorder(field => :asc).first
|
72
|
-
end
|
73
|
-
|
74
|
-
def newest_query(options={})
|
75
|
-
field = by_star_start_field(options)
|
76
|
-
all.reorder(field => :desc).first
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def previous(options={})
|
81
|
-
field = self.class.by_star_start_field(options)
|
82
|
-
self.class.lt(field => self.send(field)).reorder(field => :desc).first
|
83
|
-
end
|
84
|
-
|
85
|
-
def next(options={})
|
86
|
-
field = self.class.by_star_start_field(options)
|
87
|
-
self.class.gt(field => self.send(field)).reorder(field => :asc).first
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
1
|
+
# In keeping with Mongoid standards, this module must be included into your model class, i.e.
|
2
|
+
#
|
3
|
+
# include Mongoid::ByStar
|
4
|
+
#
|
5
|
+
module Mongoid
|
6
|
+
module ByStar
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
include ::ByStar::Base
|
11
|
+
|
12
|
+
alias_method :original_by_star_end_field, :by_star_end_field
|
13
|
+
alias_method :original_by_star_start_field, :by_star_start_field
|
14
|
+
|
15
|
+
def by_star_end_field(options = {})
|
16
|
+
database_field_name original_by_star_end_field(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def by_star_start_field(options = {})
|
20
|
+
database_field_name original_by_star_start_field(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def by_star_default_field
|
24
|
+
:created_at
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def by_star_point_query(scope, field, start_time, end_time)
|
30
|
+
range = start_time..end_time
|
31
|
+
scope.where(field => range)
|
32
|
+
end
|
33
|
+
|
34
|
+
def by_star_span_strict_query(scope, start_field, end_field, start_time, end_time)
|
35
|
+
range = start_time..end_time
|
36
|
+
scope.where(start_field => range).where(end_field => range)
|
37
|
+
end
|
38
|
+
|
39
|
+
def by_star_span_loose_query(scope, start_field, end_field, start_time, end_time, options)
|
40
|
+
index_scope = by_star_eval_index_scope(start_time, end_time, options)
|
41
|
+
scope = scope.gt(end_field => start_time).lt(start_field => end_time)
|
42
|
+
scope = scope.gte(start_field => index_scope) if index_scope
|
43
|
+
scope
|
44
|
+
end
|
45
|
+
|
46
|
+
def by_star_point_overlap_query(scope, field, time)
|
47
|
+
scope.where(field => time)
|
48
|
+
end
|
49
|
+
|
50
|
+
def by_star_span_overlap_query(scope, start_field, end_field, time, options)
|
51
|
+
index_scope = by_star_eval_index_scope(time, time, options)
|
52
|
+
scope = scope.gt(end_field => time).lte(start_field => time)
|
53
|
+
scope = scope.gte(start_field => index_scope) if index_scope
|
54
|
+
scope
|
55
|
+
end
|
56
|
+
|
57
|
+
def by_star_before_query(scope, field, time)
|
58
|
+
scope.lte(field => time)
|
59
|
+
end
|
60
|
+
|
61
|
+
def by_star_after_query(scope, field, time)
|
62
|
+
scope.gte(field => time)
|
63
|
+
end
|
64
|
+
|
65
|
+
def by_star_order(scope, order)
|
66
|
+
scope.order_by(order)
|
67
|
+
end
|
68
|
+
|
69
|
+
def oldest_query(options={})
|
70
|
+
field = by_star_start_field(options)
|
71
|
+
all.reorder(field => :asc).first
|
72
|
+
end
|
73
|
+
|
74
|
+
def newest_query(options={})
|
75
|
+
field = by_star_start_field(options)
|
76
|
+
all.reorder(field => :desc).first
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def previous(options={})
|
81
|
+
field = self.class.by_star_start_field(options)
|
82
|
+
self.class.lt(field => self.send(field)).reorder(field => :desc).first
|
83
|
+
end
|
84
|
+
|
85
|
+
def next(options={})
|
86
|
+
field = self.class.by_star_start_field(options)
|
87
|
+
self.class.gt(field => self.send(field)).reorder(field => :asc).first
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
# Backport of `reorder` method from Origin 2.1.0+
|
2
|
-
if defined?(Origin::Optional) && !Origin::Optional.method_defined?(:reorder)
|
3
|
-
module Origin
|
4
|
-
module Optional
|
5
|
-
|
6
|
-
# Instead of merging the order criteria, use this method to completely
|
7
|
-
# replace the existing ordering with the provided.
|
8
|
-
#
|
9
|
-
# @example Replace the ordering.
|
10
|
-
# optional.reorder(name: :asc)
|
11
|
-
#
|
12
|
-
# @param [ Array, Hash, String ] spec The sorting specification.
|
13
|
-
#
|
14
|
-
# @return [ Optional ] The cloned optional.
|
15
|
-
#
|
16
|
-
# @since 2.1.0
|
17
|
-
def reorder(*spec)
|
18
|
-
options.delete(:sort)
|
19
|
-
order_by(*spec)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
# Backport of `reorder` method from Origin 2.1.0+
|
2
|
+
if defined?(Origin::Optional) && !Origin::Optional.method_defined?(:reorder)
|
3
|
+
module Origin
|
4
|
+
module Optional
|
5
|
+
|
6
|
+
# Instead of merging the order criteria, use this method to completely
|
7
|
+
# replace the existing ordering with the provided.
|
8
|
+
#
|
9
|
+
# @example Replace the ordering.
|
10
|
+
# optional.reorder(name: :asc)
|
11
|
+
#
|
12
|
+
# @param [ Array, Hash, String ] spec The sorting specification.
|
13
|
+
#
|
14
|
+
# @return [ Optional ] The cloned optional.
|
15
|
+
#
|
16
|
+
# @since 2.1.0
|
17
|
+
def reorder(*spec)
|
18
|
+
options.delete(:sort)
|
19
|
+
order_by(*spec)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/by_star/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module ByStar
|
2
|
-
VERSION = '4.0.
|
3
|
-
end
|
1
|
+
module ByStar
|
2
|
+
VERSION = '4.0.1'
|
3
|
+
end
|
data/lib/by_star.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'by_star/kernel/in_time_zone'
|
2
|
-
require 'by_star/kernel/time'
|
3
|
-
require 'by_star/kernel/date'
|
4
|
-
require 'by_star/normalization'
|
5
|
-
require 'by_star/between'
|
6
|
-
require 'by_star/directional'
|
7
|
-
require 'by_star/base'
|
8
|
-
|
9
|
-
if defined?(ActiveRecord)
|
10
|
-
require 'by_star/orm/active_record/by_star'
|
11
|
-
ActiveRecord::Base.send :include, ByStar::ActiveRecord
|
12
|
-
ActiveRecord::Relation.send :extend, ByStar::ActiveRecord::ClassMethods
|
13
|
-
end
|
14
|
-
|
15
|
-
if defined?(Mongoid)
|
16
|
-
require 'by_star/orm/mongoid/reorder'
|
17
|
-
require 'by_star/orm/mongoid/by_star'
|
18
|
-
end
|
1
|
+
require 'by_star/kernel/in_time_zone'
|
2
|
+
require 'by_star/kernel/time'
|
3
|
+
require 'by_star/kernel/date'
|
4
|
+
require 'by_star/normalization'
|
5
|
+
require 'by_star/between'
|
6
|
+
require 'by_star/directional'
|
7
|
+
require 'by_star/base'
|
8
|
+
|
9
|
+
if defined?(ActiveRecord)
|
10
|
+
require 'by_star/orm/active_record/by_star'
|
11
|
+
ActiveRecord::Base.send :include, ByStar::ActiveRecord
|
12
|
+
ActiveRecord::Relation.send :extend, ByStar::ActiveRecord::ClassMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined?(Mongoid)
|
16
|
+
require 'by_star/orm/mongoid/reorder'
|
17
|
+
require 'by_star/orm/mongoid/by_star'
|
18
|
+
end
|
data/spec/database.yml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
sqlite:
|
2
|
-
adapter: sqlite3
|
3
|
-
database: by_star.sqlite3
|
4
|
-
|
5
|
-
postgres:
|
6
|
-
adapter: postgresql
|
7
|
-
database: by_star_test
|
8
|
-
username: <%= ENV.fetch("USER") || "postgres" %>
|
9
|
-
min_messages: warning
|
10
|
-
|
11
|
-
mysql:
|
12
|
-
adapter: mysql2
|
13
|
-
database: by_star_test
|
14
|
-
username: root
|
15
|
-
encoding: utf8
|
1
|
+
sqlite:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: by_star.sqlite3
|
4
|
+
|
5
|
+
postgres:
|
6
|
+
adapter: postgresql
|
7
|
+
database: by_star_test
|
8
|
+
username: <%= ENV.fetch("USER") || "postgres" %>
|
9
|
+
min_messages: warning
|
10
|
+
|
11
|
+
mysql:
|
12
|
+
adapter: mysql2
|
13
|
+
database: by_star_test
|
14
|
+
username: root
|
15
|
+
encoding: utf8
|
@@ -1,12 +1,12 @@
|
|
1
|
-
class Post < ActiveRecord::Base
|
2
|
-
end
|
3
|
-
|
4
|
-
class Appointment < ActiveRecord::Base
|
5
|
-
by_star_field index_scope: ->(start){ start - 5.days }
|
6
|
-
end
|
7
|
-
|
8
|
-
class Event < ActiveRecord::Base
|
9
|
-
by_star_field :start_time, :end_time, offset: 3.hours
|
10
|
-
|
11
|
-
default_scope ->{ order('day_of_month ASC') }
|
12
|
-
end
|
1
|
+
class Post < ActiveRecord::Base
|
2
|
+
end
|
3
|
+
|
4
|
+
class Appointment < ActiveRecord::Base
|
5
|
+
by_star_field index_scope: ->(start){ start - 5.days }
|
6
|
+
end
|
7
|
+
|
8
|
+
class Event < ActiveRecord::Base
|
9
|
+
by_star_field :start_time, :end_time, offset: 3.hours
|
10
|
+
|
11
|
+
default_scope ->{ order('day_of_month ASC') }
|
12
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
self.verbose = false
|
3
|
-
|
4
|
-
create_table :posts, force: true do |t|
|
5
|
-
t.timestamps
|
6
|
-
t.integer :day_of_month
|
7
|
-
end
|
8
|
-
|
9
|
-
create_table :events, force: true do |t|
|
10
|
-
t.timestamps
|
11
|
-
t.datetime :start_time, :end_time
|
12
|
-
t.integer :day_of_month
|
13
|
-
end
|
14
|
-
|
15
|
-
create_table :appointments, force: true do |t|
|
16
|
-
t.timestamps
|
17
|
-
t.integer :day_of_month
|
18
|
-
end
|
19
|
-
end
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
self.verbose = false
|
3
|
+
|
4
|
+
create_table :posts, force: true do |t|
|
5
|
+
t.timestamps
|
6
|
+
t.integer :day_of_month
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table :events, force: true do |t|
|
10
|
+
t.timestamps
|
11
|
+
t.datetime :start_time, :end_time
|
12
|
+
t.integer :day_of_month
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :appointments, force: true do |t|
|
16
|
+
t.timestamps
|
17
|
+
t.integer :day_of_month
|
18
|
+
end
|
19
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
class Post
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Timestamps
|
4
|
-
include Mongoid::ByStar
|
5
|
-
|
6
|
-
field :day_of_month, type: Integer
|
7
|
-
end
|
8
|
-
|
9
|
-
class Appointment
|
10
|
-
include Mongoid::Document
|
11
|
-
include Mongoid::Timestamps
|
12
|
-
include Mongoid::ByStar
|
13
|
-
|
14
|
-
field :day_of_month, type: Integer
|
15
|
-
|
16
|
-
by_star_field index_scope: ->(start){ start - 5.days }
|
17
|
-
end
|
18
|
-
|
19
|
-
class Event
|
20
|
-
include Mongoid::Document
|
21
|
-
include Mongoid::Timestamps
|
22
|
-
include Mongoid::ByStar
|
23
|
-
|
24
|
-
field :st, as: :start_time, type: Time
|
25
|
-
field :end_time, type: Time
|
26
|
-
field :day_of_month, type: Integer
|
27
|
-
|
28
|
-
by_star_field :start_time, :end_time, offset: 3.hours
|
29
|
-
|
30
|
-
default_scope ->{ order_by(day_of_month: :asc) }
|
31
|
-
end
|
1
|
+
class Post
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
include Mongoid::ByStar
|
5
|
+
|
6
|
+
field :day_of_month, type: Integer
|
7
|
+
end
|
8
|
+
|
9
|
+
class Appointment
|
10
|
+
include Mongoid::Document
|
11
|
+
include Mongoid::Timestamps
|
12
|
+
include Mongoid::ByStar
|
13
|
+
|
14
|
+
field :day_of_month, type: Integer
|
15
|
+
|
16
|
+
by_star_field index_scope: ->(start){ start - 5.days }
|
17
|
+
end
|
18
|
+
|
19
|
+
class Event
|
20
|
+
include Mongoid::Document
|
21
|
+
include Mongoid::Timestamps
|
22
|
+
include Mongoid::ByStar
|
23
|
+
|
24
|
+
field :st, as: :start_time, type: Time
|
25
|
+
field :end_time, type: Time
|
26
|
+
field :day_of_month, type: Integer
|
27
|
+
|
28
|
+
by_star_field :start_time, :end_time, offset: 3.hours
|
29
|
+
|
30
|
+
default_scope ->{ order_by(day_of_month: :asc) }
|
31
|
+
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
%w(2013-11-01
|
2
|
-
2013-11-30
|
3
|
-
2013-12-01
|
4
|
-
2013-12-05
|
5
|
-
2013-12-08
|
6
|
-
2013-12-16
|
7
|
-
2013-12-22
|
8
|
-
2013-12-25
|
9
|
-
2013-12-28
|
10
|
-
2013-12-31
|
11
|
-
2014-01-01
|
12
|
-
2014-01-01
|
13
|
-
2014-01-05
|
14
|
-
2014-01-10
|
15
|
-
2014-01-12
|
16
|
-
2014-01-20
|
17
|
-
2014-02-01
|
18
|
-
2014-02-15
|
19
|
-
2014-03-01
|
20
|
-
2014-03-15
|
21
|
-
2014-04-01
|
22
|
-
2014-04-15).map{|d| Time.zone.parse(d) + 17.hours }.each_with_index do |d, index|
|
23
|
-
Post.create!(created_at: d, updated_at: d + index.days, day_of_month: d.day)
|
24
|
-
Appointment.create!(created_at: d, day_of_month: d.day)
|
25
|
-
Event.create!(created_at: d, start_time: d - 5.days, end_time: d + 5.days, day_of_month: d.day)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Sydney timezone specific records
|
29
|
-
%w(
|
30
|
-
2020-04-05
|
31
|
-
2020-10-04
|
32
|
-
).map{|d| Date.parse(d) }.each do |d|
|
33
|
-
[1, 4, 5, 10].each do |h|
|
34
|
-
Event.create!(start_time: d + h.hour, end_time: d + h.hour + 30.minutes, created_at: Date.parse('2011-01-01').in_time_zone)
|
35
|
-
end
|
36
|
-
end
|
1
|
+
%w(2013-11-01
|
2
|
+
2013-11-30
|
3
|
+
2013-12-01
|
4
|
+
2013-12-05
|
5
|
+
2013-12-08
|
6
|
+
2013-12-16
|
7
|
+
2013-12-22
|
8
|
+
2013-12-25
|
9
|
+
2013-12-28
|
10
|
+
2013-12-31
|
11
|
+
2014-01-01
|
12
|
+
2014-01-01
|
13
|
+
2014-01-05
|
14
|
+
2014-01-10
|
15
|
+
2014-01-12
|
16
|
+
2014-01-20
|
17
|
+
2014-02-01
|
18
|
+
2014-02-15
|
19
|
+
2014-03-01
|
20
|
+
2014-03-15
|
21
|
+
2014-04-01
|
22
|
+
2014-04-15).map{|d| Time.zone.parse(d) + 17.hours }.each_with_index do |d, index|
|
23
|
+
Post.create!(created_at: d, updated_at: d + index.days, day_of_month: d.day)
|
24
|
+
Appointment.create!(created_at: d, day_of_month: d.day)
|
25
|
+
Event.create!(created_at: d, start_time: d - 5.days, end_time: d + 5.days, day_of_month: d.day)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Sydney timezone specific records
|
29
|
+
%w(
|
30
|
+
2020-04-05
|
31
|
+
2020-10-04
|
32
|
+
).map{|d| Date.parse(d) }.each do |d|
|
33
|
+
[1, 4, 5, 10].each do |h|
|
34
|
+
Event.create!(start_time: d + h.hour, end_time: d + h.hour + 30.minutes, created_at: Date.parse('2011-01-01').in_time_zone)
|
35
|
+
end
|
36
|
+
end
|
data/spec/gemfiles/Gemfile.rails
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
source 'http://rubygems.org'
|
2
|
-
|
3
|
-
gemspec path: '../../'
|
4
|
-
|
5
|
-
gem 'activerecord', github: 'rails', branch: "main"
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gemspec path: '../../'
|
4
|
+
|
5
|
+
gem 'activerecord', github: 'rails', branch: "main"
|