ruby_event_store 0.31.1 → 0.32.0

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.
@@ -0,0 +1,9 @@
1
+ RSpec.shared_examples :scheduler do |scheduler|
2
+ specify "#call" do
3
+ expect(scheduler).to respond_to(:call).with(2).arguments
4
+ end
5
+
6
+ specify "#verify" do
7
+ expect(scheduler).to respond_to(:verify).with(1).argument
8
+ end
9
+ end
@@ -2,54 +2,11 @@ module RubyEventStore
2
2
 
3
3
  # Used for building and executing the query specification.
4
4
  class Specification
5
- # @private
6
- # @api private
7
- NO_LIMIT = Object.new.freeze
8
- # @private
9
- # @api private
10
- NO_BATCH = Object.new.freeze
11
5
  DEFAULT_BATCH_SIZE = 100
12
-
13
- class Result < Struct.new(:direction, :start, :count, :stream, :batch_size)
14
- def limit?
15
- !count.equal?(NO_LIMIT)
16
- end
17
-
18
- def global_stream?
19
- stream.global?
20
- end
21
-
22
- def stream_name
23
- stream.name
24
- end
25
-
26
- def head?
27
- start.equal?(:head)
28
- end
29
-
30
- def forward?
31
- direction.equal?(:forward)
32
- end
33
-
34
- def backward?
35
- !forward?
36
- end
37
-
38
- def batched?
39
- !batch_size.equal?(NO_BATCH)
40
- end
41
- end
42
- private_constant :Result
43
-
44
6
  # @api private
45
7
  # @private
46
- attr_reader :result
47
-
48
- # @api private
49
- # @private
50
- def initialize(repository, mapper, result = Result.new(:forward, :head, NO_LIMIT, Stream.new(GLOBAL_STREAM), NO_BATCH))
51
- @mapper = mapper
52
- @repository = repository
8
+ def initialize(reader, result = SpecificationResult.new)
9
+ @reader = reader
53
10
  @result = result
54
11
  end
55
12
 
@@ -59,7 +16,7 @@ module RubyEventStore
59
16
  # @param stream_name [String] name of the stream to get events from
60
17
  # @return [Specification]
61
18
  def stream(stream_name)
62
- Specification.new(repository, mapper, result.dup.tap { |r| r.stream = Stream.new(stream_name) })
19
+ Specification.new(reader, result.dup { |r| r.stream = Stream.new(stream_name) })
63
20
  end
64
21
 
65
22
  # Limits the query to events before or after another event.
@@ -75,9 +32,9 @@ module RubyEventStore
75
32
  raise InvalidPageStart unless [:head].include?(start)
76
33
  else
77
34
  raise InvalidPageStart if start.nil? || start.empty?
78
- raise EventNotFound.new(start) unless repository.has_event?(start)
35
+ raise EventNotFound.new(start) unless reader.has_event?(start)
79
36
  end
80
- Specification.new(repository, mapper, result.dup.tap { |r| r.start = start })
37
+ Specification.new(reader, result.dup { |r| r.start = start })
81
38
  end
82
39
 
83
40
  # Sets the order of reading events to ascending (forward from the start).
@@ -85,7 +42,7 @@ module RubyEventStore
85
42
  #
86
43
  # @return [Specification]
87
44
  def forward
88
- Specification.new(repository, mapper, result.dup.tap { |r| r.direction = :forward })
45
+ Specification.new(reader, result.dup { |r| r.direction = :forward })
89
46
  end
90
47
 
91
48
  # Sets the order of reading events to descending (backward from the start).
@@ -93,7 +50,7 @@ module RubyEventStore
93
50
  #
94
51
  # @return [Specification]
95
52
  def backward
96
- Specification.new(repository, mapper, result.dup.tap { |r| r.direction = :backward })
53
+ Specification.new(reader, result.dup { |r| r.direction = :backward })
97
54
  end
98
55
 
99
56
  # Limits the query to specified number of events.
@@ -103,7 +60,7 @@ module RubyEventStore
103
60
  # @return [Specification]
104
61
  def limit(count)
105
62
  raise InvalidPageSize unless count && count > 0
106
- Specification.new(repository, mapper, result.dup.tap { |r| r.count = count })
63
+ Specification.new(reader, result.dup { |r| r.count = count })
107
64
  end
108
65
 
109
66
  # Executes the query based on the specification built up to this point.
@@ -115,9 +72,8 @@ module RubyEventStore
115
72
  def each_batch
116
73
  return to_enum(:each_batch) unless block_given?
117
74
 
118
- result_ = result.batched? ? result : result.tap { |r| r.batch_size = DEFAULT_BATCH_SIZE }
119
- repository.read(result_).each do |batch|
120
- yield batch.map { |serialized_record| mapper.serialized_record_to_event(serialized_record) }
75
+ reader.each(in_batches(result.batch_size).result) do |batch|
76
+ yield batch
121
77
  end
122
78
  end
123
79
 
@@ -149,11 +105,46 @@ module RubyEventStore
149
105
  # @param batch_size [Integer] number of events to read in a single batch
150
106
  # @return [Specification]
151
107
  def in_batches(batch_size = DEFAULT_BATCH_SIZE)
152
- Specification.new(repository, mapper, result.dup.tap { |r| r.batch_size = batch_size })
108
+ Specification.new(reader, result.dup { |r| r.read_as = :batch; r.batch_size = batch_size })
153
109
  end
154
110
  alias :in_batches_of :in_batches
155
111
 
112
+ # Specifies that only first event should be read.
113
+ # {http://railseventstore.org/docs/read/ Find out more}.
114
+ #
115
+ # @return [Specification]
116
+ def read_first
117
+ Specification.new(reader, result.dup { |r| r.read_as = :first })
118
+ end
119
+
120
+ # Specifies that only last event should be read.
121
+ # {http://railseventstore.org/docs/read/ Find out more}.
122
+ #
123
+ # @return [Specification]
124
+ def read_last
125
+ Specification.new(reader, result.dup { |r| r.read_as = :last })
126
+ end
127
+
128
+ # Executes the query based on the specification built up to this point.
129
+ # Returns the first event in specified collection of events.
130
+ # {http://railseventstore.org/docs/read/ Find out more}.
131
+ #
132
+ # @return [Event, nil]
133
+ def first
134
+ reader.one(read_first.result)
135
+ end
136
+
137
+ # Executes the query based on the specification built up to this point.
138
+ # Returns the last event in specified collection of events.
139
+ # {http://railseventstore.org/docs/read/ Find out more}.
140
+ #
141
+ # @return [Event, nil]
142
+ def last
143
+ reader.one(read_last.result)
144
+ end
145
+
146
+ attr_reader :result
156
147
  private
157
- attr_reader :repository, :mapper
148
+ attr_reader :reader
158
149
  end
159
150
  end
@@ -0,0 +1,35 @@
1
+ module RubyEventStore
2
+ # Used for fetching events based on given query specification.
3
+ class SpecificationReader
4
+ # @api private
5
+ # @private
6
+ def initialize(repository, mapper)
7
+ @repository = repository
8
+ @mapper = mapper
9
+ end
10
+
11
+ # @api private
12
+ # @private
13
+ def one(specification_result)
14
+ record = repository.read(specification_result)
15
+ mapper.serialized_record_to_event(record) if record
16
+ end
17
+
18
+ # @api private
19
+ # @private
20
+ def each(specification_result)
21
+ repository.read(specification_result).each do |batch|
22
+ yield batch.map { |serialized_record| mapper.serialized_record_to_event(serialized_record) }
23
+ end
24
+ end
25
+
26
+ # @api private
27
+ # @private
28
+ def has_event?(event_id)
29
+ repository.has_event?(event_id)
30
+ end
31
+
32
+ private
33
+ attr_reader :repository, :mapper
34
+ end
35
+ end
@@ -0,0 +1,206 @@
1
+ module RubyEventStore
2
+ class SpecificationResult
3
+ def initialize(direction: :forward,
4
+ start: :head,
5
+ count: nil,
6
+ stream: Stream.new(GLOBAL_STREAM),
7
+ read_as: :all,
8
+ batch_size: Specification::DEFAULT_BATCH_SIZE)
9
+ @attributes = Struct.new(:direction, :start, :count, :stream, :read_as, :batch_size)
10
+ .new(direction, start, count, stream, read_as, batch_size)
11
+ freeze
12
+ end
13
+
14
+ # Limited results. True if number of read elements are limited
15
+ # {http://railseventstore.org/docs/read/ Find out more}.
16
+ #
17
+ # @return [Boolean]
18
+ def limit?
19
+ !attributes.count.nil?
20
+ end
21
+
22
+ # Results limit or infinity if limit not defined
23
+ # {http://railseventstore.org/docs/read/ Find out more}.
24
+ #
25
+ # @return [Integer|Infinity]
26
+ def limit
27
+ attributes.count || Float::INFINITY
28
+ end
29
+
30
+ # Stream definition. Stream to be read or nil
31
+ # {http://railseventstore.org/docs/read/ Find out more}.
32
+ #
33
+ # @return [Stream|nil]
34
+ def stream
35
+ attributes.stream
36
+ end
37
+
38
+ # Starting position. True is starting from head
39
+ # {http://railseventstore.org/docs/read/ Find out more}.
40
+ #
41
+ # @return [Boolean]
42
+ def head?
43
+ start.equal?(:head)
44
+ end
45
+
46
+ # Starting position. Event id of starting event or :head
47
+ # {http://railseventstore.org/docs/read/ Find out more}.
48
+ #
49
+ # @return [String|Symbol]
50
+ def start
51
+ attributes.start
52
+ end
53
+
54
+ # Read direction. True is reading forward
55
+ # {http://railseventstore.org/docs/read/ Find out more}.
56
+ #
57
+ # @return [Boolean]
58
+ def forward?
59
+ get_direction.equal?(:forward)
60
+ end
61
+
62
+ # Read direction. True is reading backward
63
+ # {http://railseventstore.org/docs/read/ Find out more}.
64
+ #
65
+ # @return [Boolean]
66
+ def backward?
67
+ get_direction.equal?(:backward)
68
+ end
69
+
70
+ # Size of batch to read (only for :batch read strategy)
71
+ # {http://railseventstore.org/docs/read/ Find out more}.
72
+ #
73
+ # @return [Integer]
74
+ def batch_size
75
+ attributes.batch_size
76
+ end
77
+
78
+ # Read strategy. True if items will be read in batches
79
+ # {http://railseventstore.org/docs/read/ Find out more}.
80
+ #
81
+ # @return [Boolean]
82
+ def batched?
83
+ attributes.read_as.equal?(:batch)
84
+ end
85
+
86
+ # Read strategy. True if first item will be read
87
+ # {http://railseventstore.org/docs/read/ Find out more}.
88
+ #
89
+ # @return [Boolean]
90
+ def first?
91
+ attributes.read_as.equal?(:first)
92
+ end
93
+
94
+ # Read strategy. True if last item will be read
95
+ # {http://railseventstore.org/docs/read/ Find out more}.
96
+ #
97
+ # @return [Boolean]
98
+ def last?
99
+ attributes.read_as.equal?(:last)
100
+ end
101
+
102
+ # Read strategy. True if all items will be read
103
+ # {http://railseventstore.org/docs/read/ Find out more}.
104
+ #
105
+ # @return [Boolean]
106
+ def all?
107
+ attributes.read_as.equal?(:all)
108
+ end
109
+
110
+ # Clone [SpecificationResult]
111
+ # If block is given cloned attributes might be modified.
112
+ #
113
+ # @return [SpecificationResult]
114
+ def dup
115
+ new_attributes = attributes.dup
116
+ yield new_attributes if block_given?
117
+ SpecificationResult.new(new_attributes.to_h)
118
+ end
119
+
120
+ # Two specification attributess are equal if:
121
+ # * they are of the same class
122
+ # * have identical data (verified with eql? method)
123
+ #
124
+ # @param other_spec [SpecificationResult, Object] object to compare
125
+ #
126
+ # @return [TrueClass, FalseClass]
127
+ def ==(other_spec)
128
+ other_spec.hash.eql?(hash)
129
+ end
130
+
131
+ # @private
132
+ BIG_VALUE = 0b100010010100011110111101100001011111100101001010111110101000000
133
+
134
+ # Generates a Fixnum hash value for this object. This function
135
+ # have the property that a.eql?(b) implies a.hash == b.hash.
136
+ #
137
+ # The hash value is used along with eql? by the Hash class to
138
+ # determine if two objects reference the same hash key.
139
+ #
140
+ # This hash is based on
141
+ # * class
142
+ # * direction
143
+ # * start
144
+ # * count
145
+ # * stream
146
+ # * read_as
147
+ # * batch_size
148
+ #
149
+ # @return [Integer]
150
+ def hash
151
+ [
152
+ self.class,
153
+ get_direction,
154
+ start,
155
+ limit,
156
+ stream,
157
+ attributes.read_as,
158
+ batch_size,
159
+ ].hash ^ BIG_VALUE
160
+ end
161
+
162
+ # @deprecated Use {#limit} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
163
+ def count
164
+ warn <<~EOW
165
+ RubyEventStore::SpecificationResult#count has been deprecated.
166
+ Use RubyEventStore::SpecificationResult#limit instead.
167
+ EOW
168
+ limit
169
+ end
170
+
171
+ # @deprecated Use {#forward?} or {#backward?} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
172
+ def direction
173
+ warn <<~EOW
174
+ RubyEventStore::SpecificationResult#direction has been deprecated.
175
+ Use RubyEventStore::SpecificationResult#forward? or
176
+ RubyEventStore::SpecificationResult#backward? instead.
177
+ EOW
178
+ get_direction
179
+ end
180
+
181
+ # @deprecated Use {#stream.name} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
182
+ def stream_name
183
+ warn <<~EOW
184
+ RubyEventStore::SpecificationResult#stream_name has been deprecated.
185
+ Use RubyEventStore::SpecificationResult#stream.name instead.
186
+ EOW
187
+ stream.name
188
+ end
189
+
190
+ # @deprecated Use {#stream.global?} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
191
+ def global_stream?
192
+ warn <<~EOW
193
+ RubyEventStore::SpecificationResult#global_stream? has been deprecated.
194
+ Use RubyEventStore::SpecificationResult#stream.global? instead.
195
+ EOW
196
+ stream.global?
197
+ end
198
+
199
+ private
200
+ attr_reader :attributes
201
+
202
+ def get_direction
203
+ attributes.direction
204
+ end
205
+ end
206
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyEventStore
2
- VERSION = "0.31.1"
2
+ VERSION = "0.32.0"
3
3
  end
@@ -30,9 +30,10 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'bundler', '~> 1.15'
31
31
  spec.add_development_dependency 'rake', '~> 10.0'
32
32
  spec.add_development_dependency 'rspec', '~> 3.6'
33
- spec.add_development_dependency 'mutant-rspec', '~> 0.8.14'
33
+ spec.add_development_dependency 'mutant-rspec', '~> 0.8.17'
34
34
  spec.add_development_dependency 'parser'
35
35
  spec.add_development_dependency 'unparser'
36
36
  spec.add_development_dependency 'astrolabe'
37
37
  spec.add_development_dependency 'google-protobuf', '~> 3.5.1.2'
38
+ spec.add_development_dependency 'activesupport', '~> 5.0'
38
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.1
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-17 00:00:00.000000000 Z
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.8.14
75
+ version: 0.8.17
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.8.14
82
+ version: 0.8.17
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: parser
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 3.5.1.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: activesupport
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '5.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '5.0'
139
153
  description: Implementation of Event Store in Ruby
140
154
  email:
141
155
  - dev@arkency.com
@@ -154,15 +168,18 @@ files:
154
168
  - lib/ruby_event_store/async_proxy_strategy.rb
155
169
  - lib/ruby_event_store/batch_enumerator.rb
156
170
  - lib/ruby_event_store/client.rb
171
+ - lib/ruby_event_store/composed_dispatcher.rb
157
172
  - lib/ruby_event_store/constants.rb
158
173
  - lib/ruby_event_store/correlated_commands.rb
159
174
  - lib/ruby_event_store/deprecated_read_api_rewriter.rb
160
175
  - lib/ruby_event_store/deprecated_read_api_runner.rb
161
- - lib/ruby_event_store/deprecations.rb
162
176
  - lib/ruby_event_store/errors.rb
163
177
  - lib/ruby_event_store/event.rb
164
178
  - lib/ruby_event_store/expected_version.rb
179
+ - lib/ruby_event_store/immediate_async_dispatcher.rb
165
180
  - lib/ruby_event_store/in_memory_repository.rb
181
+ - lib/ruby_event_store/instrumented_dispatcher.rb
182
+ - lib/ruby_event_store/instrumented_repository.rb
166
183
  - lib/ruby_event_store/link_by_metadata.rb
167
184
  - lib/ruby_event_store/mappers/default.rb
168
185
  - lib/ruby_event_store/mappers/null_mapper.rb
@@ -176,8 +193,11 @@ files:
176
193
  - lib/ruby_event_store/spec/broker_lint.rb
177
194
  - lib/ruby_event_store/spec/dispatcher_lint.rb
178
195
  - lib/ruby_event_store/spec/event_repository_lint.rb
196
+ - lib/ruby_event_store/spec/scheduler_lint.rb
179
197
  - lib/ruby_event_store/spec/subscriptions_lint.rb
180
198
  - lib/ruby_event_store/specification.rb
199
+ - lib/ruby_event_store/specification_reader.rb
200
+ - lib/ruby_event_store/specification_result.rb
181
201
  - lib/ruby_event_store/stream.rb
182
202
  - lib/ruby_event_store/version.rb
183
203
  - ruby_event_store.gemspec