ruby_event_store-active_record 2.7.0 → 2.8.0

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
  SHA256:
3
- metadata.gz: da1ae3857e3ed938eedebac46e1a2ca4e8fc89be6e424f9614e29300430e8278
4
- data.tar.gz: 43f039fc3434fc542918682e788acbeb497a219f845da9d149ed041a06d021c0
3
+ metadata.gz: 0104d3bbcbf407a2c08ab36e92eae47e0b77051ea1e86f88d9d0f3af8a6ad34d
4
+ data.tar.gz: 0f3f118e8f685735c6f50f1ab2c9d389f539ca3695507192136f4d279c8fec57
5
5
  SHA512:
6
- metadata.gz: f1a893454a79f7fb541a96fb12b5fc7d41d9aaa2ac29a8d6d23a6e128dcd349a75c387135774eee641d0e879d5124c092217f6e0e8ff1bffbf4eaf9485ccb5a6
7
- data.tar.gz: 5b3a9ad5d24bff351eb8b0ae651b3d68bfc9ab5dd15fe5da2be79ed8c4aabca165cc2807f1bf1b75a6253c17287c342c820ac6d95e94bcbec23add6d2c77fa7e
6
+ metadata.gz: 042f8d47fe357e87f643a1748f76b675f2ec098a7e105037b998f71e3192d28d801d6f67fd09c4e6902240f7841d882a2aaea58d0570cb87f5fcc9b35458e6c2
7
+ data.tar.gz: 48bbdf33832cbec83891c5466483e284029042a87b6809913ee5f2c89ae980a5006bf1285ba69c6f25bb8686f820a00542160ff49ca22a478634a5b83127a08b
@@ -85,7 +85,8 @@ module RubyEventStore
85
85
  stream = @event_klass
86
86
  stream = stream.where(event_id: spec.with_ids) if spec.with_ids?
87
87
  stream = stream.where(event_type: spec.with_types) if spec.with_types?
88
- stream = ordered(stream, spec)
88
+ stream = stream.order(as_at(spec)) if spec.time_sort_by_as_at?
89
+ stream = stream.order(as_of(spec)) if spec.time_sort_by_as_of?
89
90
  stream = stream.limit(spec.limit) if spec.limit?
90
91
  stream = stream.where(start_condition_in_global_stream(spec)) if spec.start
91
92
  stream = stream.where(stop_condition_in_global_stream(spec)) if spec.stop
@@ -97,29 +98,27 @@ module RubyEventStore
97
98
  else
98
99
  stream = @stream_klass.preload(:event).where(stream: spec.stream.name)
99
100
  stream = stream.where(event_id: spec.with_ids) if spec.with_ids?
100
- stream = stream.where(@event_klass.table_name => { event_type: spec.with_types }) if spec.with_types?
101
- stream = ordered(stream.joins(:event), spec)
101
+ stream = stream.joins(:event).where(@event_klass.table_name => { event_type: spec.with_types }) if spec.with_types?
102
+ stream = stream.joins(:event).order(as_at(spec)) if spec.time_sort_by_as_at?
103
+ stream = stream.joins(:event).order(as_of(spec)) if spec.time_sort_by_as_of?
102
104
  stream = stream.order(id: order(spec))
103
105
  stream = stream.limit(spec.limit) if spec.limit?
104
106
  stream = stream.where(start_condition(spec)) if spec.start
105
107
  stream = stream.where(stop_condition(spec)) if spec.stop
106
- stream = stream.where(older_than_condition(spec)) if spec.older_than
107
- stream = stream.where(older_than_or_equal_condition(spec)) if spec.older_than_or_equal
108
- stream = stream.where(newer_than_condition(spec)) if spec.newer_than
109
- stream = stream.where(newer_than_or_equal_condition(spec)) if spec.newer_than_or_equal
108
+ stream = stream.joins(:event).where(older_than_condition(spec)) if spec.older_than
109
+ stream = stream.joins(:event).where(older_than_or_equal_condition(spec)) if spec.older_than_or_equal
110
+ stream = stream.joins(:event).where(newer_than_condition(spec)) if spec.newer_than
111
+ stream = stream.joins(:event).where(newer_than_or_equal_condition(spec)) if spec.newer_than_or_equal
110
112
  stream
111
113
  end
112
114
  end
113
115
 
114
- def ordered(stream, spec)
115
- case spec.time_sort_by
116
- when :as_at
117
- stream.order("#{@event_klass.table_name}.created_at #{order(spec)}")
118
- when :as_of
119
- stream.order("#{@event_klass.table_name}.valid_at #{order(spec)}")
120
- else
121
- stream
122
- end
116
+ def as_of(spec)
117
+ Arel.sql("COALESCE(#{@event_klass.table_name}.valid_at, #{@event_klass.table_name}.created_at) #{order(spec)}")
118
+ end
119
+
120
+ def as_at(spec)
121
+ "#{@event_klass.table_name}.created_at #{order(spec)}"
123
122
  end
124
123
 
125
124
  def start_offset_condition(specification, record_id, search_in)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module ActiveRecord
5
- VERSION = "2.7.0"
5
+ VERSION = "2.8.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-19 00:00:00.000000000 Z
11
+ date: 2023-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_event_store
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.7.0
19
+ version: 2.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.7.0
26
+ version: 2.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement