Skip to content

Commit e424b14

Browse files
Merge pull request #378 from RailsEventStore/doc/366-one-publish-method-to-rule-them-all
Use new publish API in docs [#366]
2 parents 1fc1c16 + d899f68 commit e424b14

14 files changed

+45
-45
lines changed

rails_event_store-rspec/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ In a simplest form it would read all streams backward up to a page limit (100 ev
8686

8787
```ruby
8888
event_store = RailsEventStore::Client.new
89-
event_store.publish_event(OrderPlaced.new(data: { order_id: 42 }))
89+
event_store.publish(OrderPlaced.new(data: { order_id: 42 }))
9090

9191
expect(event_store).to have_published(an_event(OrderPlaced))
9292
```
@@ -95,7 +95,7 @@ Expectation can be narrowed to the specific stream.
9595

9696
```ruby
9797
event_store = RailsEventStore::Client.new
98-
event_store.publish_event(OrderPlaced.new(data: { order_id: 42 }), stream_name: "Order$42")
98+
event_store.publish(OrderPlaced.new(data: { order_id: 42 }), stream_name: "Order$42")
9999

100100
expect(event_store).to have_published(an_event(OrderPlaced)).in_stream("Order$42")
101101
```

railseventstore.org/source/docs/correlation_causation.html.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MyEventHandler
2222
new_event = MyEvent.new(data: {foo: 'bar'})
2323
new_event.correlate_with(previous_event)
2424

25-
event_store.publish_event(new_event)
25+
event_store.publish(new_event)
2626
end
2727
end
2828

@@ -75,7 +75,7 @@ class MyEventHandler
7575
correlation_id: previous_event.correlation_id || previous_event.event_id,
7676
causation_id: previous_event.event_id
7777
) do
78-
event_store.publish_events([
78+
event_store.publish([
7979
MyEvent.new(data: {foo: 'bar'}),
8080
AnotherEvent.new(data: {baz: 'bax'}),
8181
])

railseventstore.org/source/docs/exceptions.html.md.erb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ When using Rails Event Store you have to be prepared for following errors:
77
Occurs when other writer has written to the same stream as we intended to and last stream version has changed:
88

99
```ruby
10-
client.publish_event(OrderPlaced.new, stream_name: 'Order$1', expected_version: 0)
10+
client.publish(OrderPlaced.new, stream_name: 'Order$1', expected_version: 0)
1111

1212
expect do
13-
client.publish_event(OrderCompleted.new, stream_name: 'Order$1', expected_version: 0)
13+
client.publish(OrderCompleted.new, stream_name: 'Order$1', expected_version: 0)
1414
end.to raise_error(WrongExpectedEventVersion)
1515
```
1616

@@ -22,10 +22,10 @@ Occurs when you're writing same event more than once.
2222

2323
```ruby
2424
order_placed = OrderPlaced.new
25-
client.publish_event(order_placed, stream_name: 'Order$1', expected_version: 0)
25+
client.publish(order_placed, stream_name: 'Order$1', expected_version: 0)
2626

2727
expect do
28-
client.publish_event(order_placed, stream_name: 'Order$1', expected_version: 1)
28+
client.publish(order_placed, stream_name: 'Order$1', expected_version: 1)
2929
end.to raise_error(WrongExpectedEventVersion)
3030
```
3131

@@ -39,7 +39,7 @@ If you want to have an event present in multiple streams, you have to link it wi
3939
### RubyEventStore::InvalidExpectedVersion
4040

4141
<% if version_above('0.30.0') %>
42-
Occurs when invalid `exception_version` is passed in `append`, `link`, `publish_event` or `publish_events`.
42+
Occurs when invalid `exception_version` is passed in `append_to_stream`, `link_to_stream` or `publish`.
4343
<% else %>
4444
Occurs when invalid `exception_version` is passed in `append_to_stream`, `link_to_stream`, `publish_event` or `publish_events`.
4545
<% end %>

railseventstore.org/source/docs/expected_version.html.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ There are 3 values that you can use for providing `expected_version` when publis
55
## :any
66

77
```ruby
8-
event_store.publish_event(
8+
event_store.publish(
99
event,
1010
stream_name: "Order-1",
1111
expected_version: :any,
@@ -32,7 +32,7 @@ event_store.publish_event(
3232
You start by publishing the first event in a stream with `expected_version` being `-1` (or `:none`). That means you expect no events in the stream right now.
3333

3434
```ruby
35-
event_store.publish_event(
35+
event_store.publish(
3636
event0,
3737
stream_name: "Order-1",
3838
expected_version: -1, # or :none which is a synonym
@@ -43,7 +43,7 @@ event_store.publish_event(
4343
The first published event is at position `0`. When you publish a second event you provide `expected_version: 0`.
4444

4545
```ruby
46-
event_store.publish_events(
46+
event_store.publish(
4747
[event1, event2],
4848
stream_name: "Order-1",
4949
expected_version: 0,
@@ -53,7 +53,7 @@ event_store.publish_events(
5353
We published the second and third events. Their positions are `1` and `2`. That's why when you publish the next event you need to provide `expected_version: 2`.
5454

5555
```ruby
56-
event_store.publish_event(
56+
event_store.publish(
5757
event3,
5858
stream_name: "Order-1",
5959
expected_version: 2,
@@ -81,7 +81,7 @@ This mode effectively acts as optimistic locking.
8181
## :auto
8282

8383
```ruby
84-
event_store.publish_event(
84+
event_store.publish(
8585
event,
8686
stream_name: "Order-1",
8787
expected_version: :auto,
@@ -95,7 +95,7 @@ There is a potential for a race condition between reading the `expected_version`
9595
```ruby
9696
application_lock("Order-1") do
9797
# do something with Order 1...
98-
event_store.publish_event(
98+
event_store.publish(
9999
event,
100100
stream_name: "Order-1",
101101
expected_version: :auto,

railseventstore.org/source/docs/link.html.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Order
1313
end
1414

1515
def place
16-
event_store.publish_event(
16+
event_store.publish(
1717
OrderPlaced.new(data: { id: @id }),
1818
stream_name: stream_name
1919
)

railseventstore.org/source/docs/mapping_serialization.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ end
113113

114114
event_store = Rails.configuration.event_store
115115

116-
event_store.publish_event(OrderPlaced.new(data: {
116+
event_store.publish(OrderPlaced.new(data: {
117117
'event_id' => SecureRandom.uuid,
118118
'order_id' => 1,
119119
'order_amount' => BigDecimal.new('120.55'),

railseventstore.org/source/docs/projection.html.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ You can create a projection abstract based on single stream.
55
```ruby
66
stream_name = "Customer$1"
77

8-
client.publish_event(MoneyDeposited.new(data: { amount: 10 }), stream_name: stream_name)
9-
client.publish_event(custom_event = MoneyDeposited.new(data: { amount: 20 }), stream_name: stream_name)
10-
client.publish_event(MoneyWithdrawn.new(data: { amount: 5 }), stream_name: stream_name)
8+
client.publish(MoneyDeposited.new(data: { amount: 10 }), stream_name: stream_name)
9+
client.publish(custom_event = MoneyDeposited.new(data: { amount: 20 }), stream_name: stream_name)
10+
client.publish(MoneyWithdrawn.new(data: { amount: 5 }), stream_name: stream_name)
1111

1212
account_balance = RailsEventStore::Projection.
1313
from_stream(stream_name).
@@ -38,10 +38,10 @@ account_cashflow.run(client) # => {total: 35}
3838
## Projection based on multiple streams
3939

4040
```ruby
41-
client.publish_event(MoneyDeposited.new(data: { amount: 15 }), stream_name: "Customer$1")
42-
client.publish_event(MoneyDeposited.new(data: { amount: 25 }), stream_name: "Customer$2")
43-
client.publish_event(custom_event = MoneyWithdrawn.new(data: { amount: 10 }), stream_name: "Customer$3")
44-
client.publish_event(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$3")
41+
client.publish(MoneyDeposited.new(data: { amount: 15 }), stream_name: "Customer$1")
42+
client.publish(MoneyDeposited.new(data: { amount: 25 }), stream_name: "Customer$2")
43+
client.publish(custom_event = MoneyWithdrawn.new(data: { amount: 10 }), stream_name: "Customer$3")
44+
client.publish(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$3")
4545

4646
account_balance = RailsEventStore::Projection.
4747
from_stream("Customer$1", "Customer$3").
@@ -61,10 +61,10 @@ account_balance.run(client, [:head, custom_event.event_id]) # => {total: -5}
6161
## Projection based on all streams
6262

6363
```ruby
64-
client.publish_event(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$1")
65-
client.publish_event(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$2")
66-
client.publish_event(custom_event = MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$3")
67-
client.publish_event(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$4")
64+
client.publish(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$1")
65+
client.publish(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$2")
66+
client.publish(custom_event = MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$3")
67+
client.publish(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$4")
6868

6969
account_balance = RailsEventStore::Projection.
7070
from_all_streams.

railseventstore.org/source/docs/protobuf.html.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ event = RubyEventStore::Proto.new(
7979
customer_id: 123,
8080
)
8181
)
82-
event_store.publish_event(event, stream_name: "Order-K3THNX9")
82+
event_store.publish(event, stream_name: "Order-K3THNX9")
8383
```
8484

8585
## Retrieving

railseventstore.org/source/docs/publish.html.md.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ OrderPlaced = Class.new(RailsEventStore::Event)
1515

1616
## Publishing an event
1717

18-
Then you can use `publish_event` or `publish_events` method.
18+
Then you can use `publish` method.
1919

2020
```ruby
2121
stream_name = "order_1"
@@ -26,7 +26,7 @@ event = OrderPlaced.new(data: {
2626
})
2727

2828
#publishing an event for a specific stream
29-
event_store.publish_event(event, stream_name: stream_name)
29+
event_store.publish(event, stream_name: stream_name)
3030
```
3131

3232
## Publishing an event with optimistic locking
@@ -40,7 +40,7 @@ event = OrderPlaced.new(data: {
4040
festival_id: "b2d506fd-409d-4ec7-b02f-c6d2295c7edd"
4141
})
4242

43-
event_store.publish_event(
43+
event_store.publish(
4444
event,
4545
stream_name: "order_1",
4646
expected_version: 3 # the position of the last
@@ -64,7 +64,7 @@ For more information about when should you use which one, read [expected_version
6464
Providing `stream_name` is optional (but recommended).
6565

6666
```ruby
67-
event_store.publish_event(event)
67+
event_store.publish(event)
6868
```
6969

7070
<% if version_above('0.29.0') %>

railseventstore.org/source/docs/pubsub.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CancelOrdersService
3232
order_id: order_id,
3333
)
3434
order.cancel!
35-
event_store.publish_event(
35+
event_store.publish(
3636
OrderCancelled.new(data: {
3737
order_id: order.id,
3838
customer_id: order.customer_id,

0 commit comments

Comments
 (0)