Skip to content

Commit e65d0bd

Browse files
committed
Refactor
1 parent 7805b1b commit e65d0bd

File tree

3 files changed

+52
-54
lines changed

3 files changed

+52
-54
lines changed

ruby_event_store/lib/ruby_event_store.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
require_relative "ruby_event_store/client"
1111
require_relative "ruby_event_store/metadata"
1212
require_relative "ruby_event_store/specification"
13-
require_relative "ruby_event_store/specification_result"
1413
require_relative "ruby_event_store/specification_reader"
1514
require_relative "ruby_event_store/event"
1615
require_relative "ruby_event_store/stream"

ruby_event_store/lib/ruby_event_store/specification.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,56 @@
33
module RubyEventStore
44
# Used for building and executing the query specification.
55
class Specification
6+
Result =
7+
Data.define(
8+
:direction,
9+
:start,
10+
:stop,
11+
:older_than,
12+
:older_than_or_equal,
13+
:newer_than,
14+
:newer_than_or_equal,
15+
:time_sort_by,
16+
:limit,
17+
:stream,
18+
:read_as,
19+
:batch_size,
20+
:with_ids,
21+
:with_types,
22+
) do
23+
def initialize(
24+
direction: :forward,
25+
start: nil,
26+
stop: nil,
27+
older_than: nil,
28+
older_than_or_equal: nil,
29+
newer_than: nil,
30+
newer_than_or_equal: nil,
31+
time_sort_by: nil,
32+
limit: nil,
33+
stream: Stream.new(GLOBAL_STREAM),
34+
read_as: :all,
35+
batch_size: Specification::DEFAULT_BATCH_SIZE,
36+
with_ids: nil,
37+
with_types: nil
38+
)
39+
super
40+
end
41+
42+
def limit? = !to_h[:limit].nil?
43+
def limit = to_h[:limit] || Float::INFINITY
44+
def forward? = direction.equal?(:forward)
45+
def backward? = direction.equal?(:backward)
46+
def with_ids? = !with_ids.nil?
47+
def with_types? = !(with_types || []).empty?
48+
def batched? = read_as.equal?(:batch)
49+
def first? = read_as.equal?(:first)
50+
def last? = read_as.equal?(:last)
51+
def all? = read_as.equal?(:all)
52+
def time_sort_by_as_at? = time_sort_by.equal?(:as_at)
53+
def time_sort_by_as_of? = time_sort_by.equal?(:as_of)
54+
end
55+
656
DEFAULT_BATCH_SIZE = 100
757

858
# @api private
@@ -315,4 +365,6 @@ def events(event_ids)
315365

316366
attr_reader :reader
317367
end
368+
369+
SpecificationResult = Specification::Result
318370
end

ruby_event_store/lib/ruby_event_store/specification_result.rb

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)