ruby_event_store 0.36.0 → 0.37.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.
@@ -27,9 +27,14 @@ module RubyEventStore
27
27
  # #direction
28
28
  # @return [Specification]
29
29
  def from(start)
30
+ if start.equal?(:head)
31
+ warn <<~EOW
32
+ `:head` has been deprecated. Use event_id or skip from instead.
33
+ EOW
34
+ end
30
35
  case start
31
36
  when Symbol
32
- raise InvalidPageStart unless [:head].include?(start)
37
+ raise InvalidPageStart unless start.equal?(:head)
33
38
  else
34
39
  raise InvalidPageStart if start.nil? || start.empty?
35
40
  raise EventNotFound.new(start) unless reader.has_event?(start)
@@ -37,6 +42,17 @@ module RubyEventStore
37
42
  Specification.new(reader, result.dup { |r| r.start = start })
38
43
  end
39
44
 
45
+ # Limits the query to events before or after another event.
46
+ # {http://railseventstore.org/docs/read/ Find out more}.
47
+ #
48
+ # @param start [String] id of event to start reading from.
49
+ # @return [Specification]
50
+ def to(stop)
51
+ raise InvalidPageStop if stop.nil? || stop.empty?
52
+ raise EventNotFound.new(stop) unless reader.has_event?(stop)
53
+ Specification.new(reader, result.dup { |r| r.stop = stop })
54
+ end
55
+
40
56
  # Sets the order of reading events to ascending (forward from the start).
41
57
  # {http://railseventstore.org/docs/read/ Find out more}.
42
58
  #
@@ -91,6 +107,27 @@ module RubyEventStore
91
107
  end
92
108
  end
93
109
 
110
+ # Executes the query based on the specification built up to this point
111
+ # and maps the result using provided block.
112
+ # {http://railseventstore.org/docs/read/ Find out more}.
113
+ #
114
+ # @return [Array] of mapped result
115
+ def map(&block)
116
+ raise ArgumentError.new("Block must be given") unless block_given?
117
+ each.map(&block)
118
+ end
119
+
120
+ # Reduces the results of the query based on the specification
121
+ # built up to this point result using provided block.
122
+ # {http://railseventstore.org/docs/read/ Find out more}.
123
+ #
124
+ # @accumulator starting state for reduce operation
125
+ # @return reduce result as defined by block given
126
+ def reduce(accumulator = nil, &block)
127
+ raise ArgumentError.new("Block must be given") unless block_given?
128
+ each.reduce(accumulator, &block)
129
+ end
130
+
94
131
  # Calculates the size of result set based on the specification build up to this point.
95
132
  # {http://railseventstore.org/docs/read/ Find out more}.
96
133
  #
@@ -160,14 +197,15 @@ module RubyEventStore
160
197
  reader.one(read_last.result)
161
198
  end
162
199
 
163
- # Limits the query to certain event types.
200
+ # Limits the query to certain event type(s).
164
201
  # {http://railseventstore.org/docs/read/ Find out more}.
165
202
  #
166
- # @types [Array(Class)] types of event to look for.
203
+ # @types [Class, Array(Class)] types of event to look for.
167
204
  # @return [Specification]
168
- def of_type(types)
169
- Specification.new(reader, result.dup{ |r| r.with_types = types })
205
+ def of_type(*types)
206
+ Specification.new(reader, result.dup{ |r| r.with_types = types.flatten })
170
207
  end
208
+ alias_method :of_types, :of_type
171
209
 
172
210
  # Limits the query to certain events by given even ids.
173
211
  # {http://railseventstore.org/docs/read/ Find out more}.
@@ -2,14 +2,15 @@ module RubyEventStore
2
2
  class SpecificationResult
3
3
  def initialize(direction: :forward,
4
4
  start: :head,
5
+ stop: nil,
5
6
  count: nil,
6
7
  stream: Stream.new(GLOBAL_STREAM),
7
8
  read_as: :all,
8
9
  batch_size: Specification::DEFAULT_BATCH_SIZE,
9
10
  with_ids: nil,
10
11
  with_types: nil)
11
- @attributes = Struct.new(:direction, :start, :count, :stream, :read_as, :batch_size, :with_ids, :with_types)
12
- .new(direction, start, count, stream, read_as, batch_size, with_ids, with_types)
12
+ @attributes = Struct.new(:direction, :start, :stop, :count, :stream, :read_as, :batch_size, :with_ids, :with_types)
13
+ .new(direction, start, stop, count, stream, read_as, batch_size, with_ids, with_types)
13
14
  freeze
14
15
  end
15
16
 
@@ -53,6 +54,14 @@ module RubyEventStore
53
54
  attributes.start
54
55
  end
55
56
 
57
+ # Stop position. Event id of stopping event
58
+ # {http://railseventstore.org/docs/read/ Find out more}.
59
+ #
60
+ # @return [String|Symbol]
61
+ def stop
62
+ attributes.stop
63
+ end
64
+
56
65
  # Read direction. True is reading forward
57
66
  # {http://railseventstore.org/docs/read/ Find out more}.
58
67
  #
@@ -175,6 +184,7 @@ module RubyEventStore
175
184
  # * class
176
185
  # * direction
177
186
  # * start
187
+ # * stop
178
188
  # * count
179
189
  # * stream
180
190
  # * read_as
@@ -188,6 +198,7 @@ module RubyEventStore
188
198
  self.class,
189
199
  get_direction,
190
200
  start,
201
+ stop,
191
202
  limit,
192
203
  stream,
193
204
  attributes.read_as,
@@ -197,43 +208,6 @@ module RubyEventStore
197
208
  ].hash ^ BIG_VALUE
198
209
  end
199
210
 
200
- # @deprecated Use {#limit} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
201
- def count
202
- warn <<~EOW
203
- RubyEventStore::SpecificationResult#count has been deprecated.
204
- Use RubyEventStore::SpecificationResult#limit instead.
205
- EOW
206
- limit
207
- end
208
-
209
- # @deprecated Use {#forward?} or {#backward?} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
210
- def direction
211
- warn <<~EOW
212
- RubyEventStore::SpecificationResult#direction has been deprecated.
213
- Use RubyEventStore::SpecificationResult#forward? or
214
- RubyEventStore::SpecificationResult#backward? instead.
215
- EOW
216
- get_direction
217
- end
218
-
219
- # @deprecated Use {#stream.name} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
220
- def stream_name
221
- warn <<~EOW
222
- RubyEventStore::SpecificationResult#stream_name has been deprecated.
223
- Use RubyEventStore::SpecificationResult#stream.name instead.
224
- EOW
225
- stream.name
226
- end
227
-
228
- # @deprecated Use {#stream.global?} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.32.0 More info}
229
- def global_stream?
230
- warn <<~EOW
231
- RubyEventStore::SpecificationResult#global_stream? has been deprecated.
232
- Use RubyEventStore::SpecificationResult#stream.global? instead.
233
- EOW
234
- stream.global?
235
- end
236
-
237
211
  private
238
212
  attr_reader :attributes
239
213
 
@@ -1,3 +1,3 @@
1
1
  module RubyEventStore
2
- VERSION = "0.36.0"
2
+ VERSION = "0.37.0"
3
3
  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.36.0
4
+ version: 0.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-22 00:00:00.000000000 Z
11
+ date: 2019-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -27,8 +27,7 @@ dependencies:
27
27
  description: Implementation of Event Store in Ruby
28
28
  email:
29
29
  - dev@arkency.com
30
- executables:
31
- - res-deprecated-read-api-migrator
30
+ executables: []
32
31
  extensions: []
33
32
  extra_rdoc_files: []
34
33
  files:
@@ -36,15 +35,12 @@ files:
36
35
  - Gemfile
37
36
  - Makefile
38
37
  - README.md
39
- - exe/res-deprecated-read-api-migrator
40
38
  - lib/ruby_event_store.rb
41
39
  - lib/ruby_event_store/batch_enumerator.rb
42
40
  - lib/ruby_event_store/client.rb
43
41
  - lib/ruby_event_store/composed_dispatcher.rb
44
42
  - lib/ruby_event_store/constants.rb
45
43
  - lib/ruby_event_store/correlated_commands.rb
46
- - lib/ruby_event_store/deprecated_read_api_rewriter.rb
47
- - lib/ruby_event_store/deprecated_read_api_runner.rb
48
44
  - lib/ruby_event_store/errors.rb
49
45
  - lib/ruby_event_store/event.rb
50
46
  - lib/ruby_event_store/expected_version.rb
@@ -54,6 +50,7 @@ files:
54
50
  - lib/ruby_event_store/instrumented_repository.rb
55
51
  - lib/ruby_event_store/link_by_metadata.rb
56
52
  - lib/ruby_event_store/mappers/default.rb
53
+ - lib/ruby_event_store/mappers/instrumented_mapper.rb
57
54
  - lib/ruby_event_store/mappers/null_mapper.rb
58
55
  - lib/ruby_event_store/mappers/protobuf.rb
59
56
  - lib/ruby_event_store/metadata.rb
@@ -64,6 +61,7 @@ files:
64
61
  - lib/ruby_event_store/serialized_record.rb
65
62
  - lib/ruby_event_store/spec/broker_lint.rb
66
63
  - lib/ruby_event_store/spec/dispatcher_lint.rb
64
+ - lib/ruby_event_store/spec/event_lint.rb
67
65
  - lib/ruby_event_store/spec/event_repository_lint.rb
68
66
  - lib/ruby_event_store/spec/scheduler_lint.rb
69
67
  - lib/ruby_event_store/spec/subscriptions_lint.rb
@@ -97,7 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
95
  - !ruby/object:Gem::Version
98
96
  version: '0'
99
97
  requirements: []
100
- rubygems_version: 3.0.2
98
+ rubyforge_project:
99
+ rubygems_version: 2.7.6
101
100
  signing_key:
102
101
  specification_version: 4
103
102
  summary: Event Store in Ruby
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- begin
4
- require 'ruby_event_store/deprecated_read_api_rewriter'
5
- require 'ruby_event_store/deprecated_read_api_runner'
6
- rescue LoadError
7
- warn <<-EOS
8
-
9
- You need following gems in Gemfile in order to use this script:
10
-
11
- gem 'parser'
12
- gem 'unparser'
13
- gem 'astrolabe'
14
-
15
- EOS
16
- exit(2)
17
- end
18
-
19
- RubyEventStore::DeprecatedReadAPIRunner.go(ARGV)
@@ -1,78 +0,0 @@
1
- require 'parser/current'
2
- require 'unparser'
3
- require 'ruby_event_store'
4
-
5
-
6
- module RubyEventStore
7
- class DeprecatedReadAPIRewriter < ::Parser::TreeRewriter
8
- DEPRECATED_READER_METHODS = [
9
- :read_all_streams_backward,
10
- :read_events_backward,
11
- :read_stream_events_backward,
12
- :read_all_streams_forward,
13
- :read_events_forward,
14
- :read_stream_events_forward
15
- ]
16
- private_constant :DEPRECATED_READER_METHODS
17
-
18
- def on_send(node)
19
- node.each_descendant(:send) { |desc_node| on_send(desc_node) }
20
-
21
- _, method_name, *args = node.children
22
- return unless DEPRECATED_READER_METHODS.include?(method_name)
23
- replace_range = node.location.selector
24
- replace_range = replace_range.join(node.location.end) if node.location.end
25
-
26
- case method_name
27
- when :read_all_streams_backward, :read_events_backward
28
- rewrite_api("read.backward", replace_range, **parse_args(args))
29
- when :read_stream_events_backward
30
- rewrite_api("read.backward", replace_range, count: nil, **parse_args(args))
31
- when :read_all_streams_forward, :read_events_forward
32
- rewrite_api("read", replace_range, **parse_args(args))
33
- when :read_stream_events_forward
34
- rewrite_api("read", replace_range, count: nil, **parse_args(args))
35
- end
36
- end
37
-
38
- def rewrite_api(query, range, start: nil, count: PAGE_SIZE, stream: nil)
39
- query << ".stream(#{stream})" if stream
40
- query << ".from(#{start})" if start
41
- query << ".limit(#{count})" if count
42
-
43
- replace(range, "#{query}.to_a")
44
- end
45
-
46
- def parse_args(args)
47
- return {} if args.empty?
48
-
49
- case args.size
50
- when 1
51
- case args[0].type
52
- when :hash
53
- stream_name, kwargs = nil, args[0]
54
- else
55
- stream_name, kwargs = parse_value(args[0]), AST::Node.new(:hash)
56
- end
57
- else
58
- stream_name, kwargs = parse_value(args[0]), args[1]
59
- end
60
-
61
- kwargs
62
- .children
63
- .reduce({stream: stream_name}) do |memo, pair|
64
- keyword, value = pair.children
65
- memo[parse_keyword(keyword)] = parse_value(value)
66
- memo
67
- end
68
- end
69
-
70
- def parse_value(node)
71
- Unparser.unparse(node)
72
- end
73
-
74
- def parse_keyword(node)
75
- node.children[0].to_sym
76
- end
77
- end
78
- end
@@ -1,64 +0,0 @@
1
- require 'parser/runner'
2
- require 'tempfile'
3
- require 'astrolabe/builder'
4
-
5
-
6
- module RubyEventStore
7
- class DeprecatedReadAPIRunner < Parser::Runner
8
- attr_reader :rewriter, :parser_class, :modify
9
-
10
- def initialize
11
- super
12
- @rewriter = DeprecatedReadAPIRewriter.new
13
- end
14
-
15
- def runner_name
16
- "res-deprecated-read-api-migrator"
17
- end
18
-
19
- def setup_option_parsing(opts)
20
- super(opts)
21
-
22
- opts.on '-m', '--modify' do
23
- @modify = true
24
- end
25
- end
26
-
27
- def process(buffer)
28
- parser = parser_class.new(Astrolabe::Builder.new)
29
- new_source = rewriter.rewrite(buffer, parser.parse(buffer))
30
- new_buffer = Parser::Source::Buffer.new(buffer.name + '|after res-deprecated-read-api-migrator')
31
- new_buffer.source = new_source
32
-
33
- if !modify
34
- old = Tempfile.new('old')
35
- old.write(buffer.source + "\n")
36
- old.flush
37
-
38
- new = Tempfile.new('new')
39
- new.write(new_source + "\n")
40
- new.flush
41
-
42
- IO.popen("diff -u #{old.path} #{new.path}") do |io|
43
- $stderr.write(
44
- io.read
45
- .sub(/^---.*/, "--- #{buffer.name}")
46
- .sub(/^\+\+\+.*/, "+++ #{new_buffer.name}")
47
- )
48
- end
49
- exit(1)
50
- end
51
-
52
- if File.exist?(buffer.name)
53
- File.open(buffer.name, 'w') do |file|
54
- file.write(new_source)
55
- end
56
- else
57
- if input_size > 1
58
- puts "Rewritten content of #{buffer.name}:"
59
- end
60
- puts new_source
61
- end
62
- end
63
- end
64
- end