Class: Messaging::Write::Substitute::Write
- Inherits:
-
Object
- Object
- Messaging::Write::Substitute::Write
show all
- Includes:
- Messaging::Write
- Defined in:
- lib/messaging/write/substitute.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included, #initial, #message_data_batch, register_telemetry_sink, #reply
Instance Attribute Details
#raise_expected_version_error ⇒ Object
18
19
20
|
# File 'lib/messaging/write/substitute.rb', line 18
def raise_expected_version_error
@raise_expected_version_error ||= false
end
|
#sink ⇒ Object
Returns the value of attribute sink.
16
17
18
|
# File 'lib/messaging/write/substitute.rb', line 16
def sink
@sink
end
|
Class Method Details
.build(session: nil) ⇒ Object
23
24
25
26
27
|
# File 'lib/messaging/write/substitute.rb', line 23
def self.build(session: nil)
new.tap do |instance|
::Telemetry.configure instance
end
end
|
Instance Method Details
#call(*args, **keyword_args) ⇒ Object
Also known as:
write
29
30
31
32
|
# File 'lib/messaging/write/substitute.rb', line 29
def call(*args, **keyword_args)
raise MessageStore::ExpectedVersion::Error if raise_expected_version_error
super(*args, **keyword_args)
end
|
#message_replies(&blk) ⇒ Object
147
148
149
150
151
152
153
154
155
|
# File 'lib/messaging/write/substitute.rb', line 147
def message_replies(&blk)
if blk.nil?
return sink.replied_records.map { |record| record.data.message }
end
sink.replied_records.select do |record|
blk.call(record.data.message, record.data.stream_name)
end.map { |record| record.data.message }
end
|
#message_writes(&blk) ⇒ Object
126
127
128
129
130
131
132
133
134
|
# File 'lib/messaging/write/substitute.rb', line 126
def message_writes(&blk)
if blk.nil?
return sink.written_records.map { |record| record.data.message }
end
sink.written_records.select do |record|
blk.call(record.data.message, record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
end.map { |record| record.data.message }
end
|
#one_message_reply(&blk) ⇒ Object
Also known as:
one_reply
157
158
159
160
161
162
163
164
165
|
# File 'lib/messaging/write/substitute.rb', line 157
def one_message_reply(&blk)
messages = message_replies(&blk)
if messages.length > 1
raise Substitute::Error, "More than one matching message reply was written"
end
messages.first
end
|
#one_message_write(&blk) ⇒ Object
Also known as:
one_message
136
137
138
139
140
141
142
143
144
|
# File 'lib/messaging/write/substitute.rb', line 136
def one_message_write(&blk)
messages = message_writes(&blk)
if messages.length > 1
raise Substitute::Error, "More than one matching message was written"
end
messages.first
end
|
#raise_expected_version_error! ⇒ Object
35
36
37
38
|
# File 'lib/messaging/write/substitute.rb', line 35
def raise_expected_version_error!
self.raise_expected_version_error = true
nil
end
|
#replied?(message = nil, &blk) ⇒ Boolean
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/messaging/write/substitute.rb', line 93
def replied?(message=nil, &blk)
if message.nil?
if blk.nil?
return sink.recorded_replied?
end
return sink.recorded_replied? do |record|
blk.call(record.data.message, record.data.stream_name)
end
end
written = sink.recorded_replied? do |record|
record.data.message == message
end
if !written
return false
end
if blk.nil?
return true
end
sink.recorded_replied? do |record|
blk.call(record.data.stream_name)
end
end
|
#replies(&blk) ⇒ Object
83
84
85
86
87
88
89
90
91
|
# File 'lib/messaging/write/substitute.rb', line 83
def replies(&blk)
if blk.nil?
return sink.replied_records
end
sink.replied_records.select do |record|
blk.call(record.data.message, record.data.stream_name)
end
end
|
#writes(&blk) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/messaging/write/substitute.rb', line 40
def writes(&blk)
if blk.nil?
return sink.written_records
end
sink.written_records.select do |record|
blk.call(record.data.message, record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
end
end
|
#written?(message = nil, &blk) ⇒ Boolean
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/messaging/write/substitute.rb', line 50
def written?(message=nil, &blk)
if message.nil?
if blk.nil?
return sink.recorded_written?
end
return sink.recorded_written? do |record|
blk.call(record.data.message, record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
end
end
written = sink.recorded_written? do |record|
record.data.message == message
end
if !written
return false
end
if blk.nil?
return true
end
sink.recorded_written? do |record|
blk.call(record.data.stream_name, record.data.expected_version, record.data.reply_stream_name)
end
end
|