Skip to content

Commit

Permalink
Merge pull request #378 from RailsEventStore/doc/366-one-publish-meth…
Browse files Browse the repository at this point in the history
…od-to-rule-them-all

Use new publish API in docs [#366]
  • Loading branch information
mostlyobvious authored Jul 17, 2018
2 parents 1fc1c16 + d899f68 commit e424b14
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions rails_event_store-rspec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ In a simplest form it would read all streams backward up to a page limit (100 ev

```ruby
event_store = RailsEventStore::Client.new
event_store.publish_event(OrderPlaced.new(data: { order_id: 42 }))
event_store.publish(OrderPlaced.new(data: { order_id: 42 }))

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

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

expect(event_store).to have_published(an_event(OrderPlaced)).in_stream("Order$42")
```
Expand Down
4 changes: 2 additions & 2 deletions railseventstore.org/source/docs/correlation_causation.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MyEventHandler
new_event = MyEvent.new(data: {foo: 'bar'})
new_event.correlate_with(previous_event)

event_store.publish_event(new_event)
event_store.publish(new_event)
end
end

Expand Down Expand Up @@ -75,7 +75,7 @@ class MyEventHandler
correlation_id: previous_event.correlation_id || previous_event.event_id,
causation_id: previous_event.event_id
) do
event_store.publish_events([
event_store.publish([
MyEvent.new(data: {foo: 'bar'}),
AnotherEvent.new(data: {baz: 'bax'}),
])
Expand Down
10 changes: 5 additions & 5 deletions railseventstore.org/source/docs/exceptions.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ When using Rails Event Store you have to be prepared for following errors:
Occurs when other writer has written to the same stream as we intended to and last stream version has changed:

```ruby
client.publish_event(OrderPlaced.new, stream_name: 'Order$1', expected_version: 0)
client.publish(OrderPlaced.new, stream_name: 'Order$1', expected_version: 0)

expect do
client.publish_event(OrderCompleted.new, stream_name: 'Order$1', expected_version: 0)
client.publish(OrderCompleted.new, stream_name: 'Order$1', expected_version: 0)
end.to raise_error(WrongExpectedEventVersion)
```

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

```ruby
order_placed = OrderPlaced.new
client.publish_event(order_placed, stream_name: 'Order$1', expected_version: 0)
client.publish(order_placed, stream_name: 'Order$1', expected_version: 0)

expect do
client.publish_event(order_placed, stream_name: 'Order$1', expected_version: 1)
client.publish(order_placed, stream_name: 'Order$1', expected_version: 1)
end.to raise_error(WrongExpectedEventVersion)
```

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

<% if version_above('0.30.0') %>
Occurs when invalid `exception_version` is passed in `append`, `link`, `publish_event` or `publish_events`.
Occurs when invalid `exception_version` is passed in `append_to_stream`, `link_to_stream` or `publish`.
<% else %>
Occurs when invalid `exception_version` is passed in `append_to_stream`, `link_to_stream`, `publish_event` or `publish_events`.
<% end %>
Expand Down
12 changes: 6 additions & 6 deletions railseventstore.org/source/docs/expected_version.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ There are 3 values that you can use for providing `expected_version` when publis
## :any

```ruby
event_store.publish_event(
event_store.publish(
event,
stream_name: "Order-1",
expected_version: :any,
Expand All @@ -32,7 +32,7 @@ event_store.publish_event(
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.

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

```ruby
event_store.publish_events(
event_store.publish(
[event1, event2],
stream_name: "Order-1",
expected_version: 0,
Expand All @@ -53,7 +53,7 @@ event_store.publish_events(
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`.

```ruby
event_store.publish_event(
event_store.publish(
event3,
stream_name: "Order-1",
expected_version: 2,
Expand Down Expand Up @@ -81,7 +81,7 @@ This mode effectively acts as optimistic locking.
## :auto

```ruby
event_store.publish_event(
event_store.publish(
event,
stream_name: "Order-1",
expected_version: :auto,
Expand All @@ -95,7 +95,7 @@ There is a potential for a race condition between reading the `expected_version`
```ruby
application_lock("Order-1") do
# do something with Order 1...
event_store.publish_event(
event_store.publish(
event,
stream_name: "Order-1",
expected_version: :auto,
Expand Down
2 changes: 1 addition & 1 deletion railseventstore.org/source/docs/link.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Order
end

def place
event_store.publish_event(
event_store.publish(
OrderPlaced.new(data: { id: @id }),
stream_name: stream_name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ end

event_store = Rails.configuration.event_store

event_store.publish_event(OrderPlaced.new(data: {
event_store.publish(OrderPlaced.new(data: {
'event_id' => SecureRandom.uuid,
'order_id' => 1,
'order_amount' => BigDecimal.new('120.55'),
Expand Down
22 changes: 11 additions & 11 deletions railseventstore.org/source/docs/projection.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ You can create a projection abstract based on single stream.
```ruby
stream_name = "Customer$1"

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

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

```ruby
client.publish_event(MoneyDeposited.new(data: { amount: 15 }), stream_name: "Customer$1")
client.publish_event(MoneyDeposited.new(data: { amount: 25 }), stream_name: "Customer$2")
client.publish_event(custom_event = MoneyWithdrawn.new(data: { amount: 10 }), stream_name: "Customer$3")
client.publish_event(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$3")
client.publish(MoneyDeposited.new(data: { amount: 15 }), stream_name: "Customer$1")
client.publish(MoneyDeposited.new(data: { amount: 25 }), stream_name: "Customer$2")
client.publish(custom_event = MoneyWithdrawn.new(data: { amount: 10 }), stream_name: "Customer$3")
client.publish(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$3")

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

```ruby
client.publish_event(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$1")
client.publish_event(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$2")
client.publish_event(custom_event = MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$3")
client.publish_event(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$4")
client.publish(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$1")
client.publish(MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$2")
client.publish(custom_event = MoneyDeposited.new(data: { amount: 10 }), stream_name: "Customer$3")
client.publish(MoneyWithdrawn.new(data: { amount: 20 }), stream_name: "Customer$4")

account_balance = RailsEventStore::Projection.
from_all_streams.
Expand Down
2 changes: 1 addition & 1 deletion railseventstore.org/source/docs/protobuf.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ event = RubyEventStore::Proto.new(
customer_id: 123,
)
)
event_store.publish_event(event, stream_name: "Order-K3THNX9")
event_store.publish(event, stream_name: "Order-K3THNX9")
```

## Retrieving
Expand Down
8 changes: 4 additions & 4 deletions railseventstore.org/source/docs/publish.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OrderPlaced = Class.new(RailsEventStore::Event)

## Publishing an event

Then you can use `publish_event` or `publish_events` method.
Then you can use `publish` method.

```ruby
stream_name = "order_1"
Expand All @@ -26,7 +26,7 @@ event = OrderPlaced.new(data: {
})

#publishing an event for a specific stream
event_store.publish_event(event, stream_name: stream_name)
event_store.publish(event, stream_name: stream_name)
```

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

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

```ruby
event_store.publish_event(event)
event_store.publish(event)
```

<% if version_above('0.29.0') %>
Expand Down
2 changes: 1 addition & 1 deletion railseventstore.org/source/docs/pubsub.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CancelOrdersService
order_id: order_id,
)
order.cancel!
event_store.publish_event(
event_store.publish(
OrderCancelled.new(data: {
order_id: order.id,
customer_id: order.customer_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ event.metadata # empty, unless you provided your own data called 'metadata'.
If you publish an event, the special field called `metadata` will get filled in with request details:

```ruby
event_store.publish_event(MyEvent.new(data: {foo: 'bar'}))
event_store.publish(MyEvent.new(data: {foo: 'bar'}))

<% if version_above('0.29.0') %>
my_event = event_store.read_all_streams_backward(count: 1).first
Expand Down
4 changes: 2 additions & 2 deletions railseventstore.org/source/docs/rspec.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ In a simplest form it would read all streams backward up to a page limit (100 ev

```ruby
event_store = RailsEventStore::Client.new
event_store.publish_event(OrderPlaced.new(data: { order_id: 42 }))
event_store.publish(OrderPlaced.new(data: { order_id: 42 }))

expect(event_store).to have_published(an_event(OrderPlaced))
```
Expand All @@ -93,7 +93,7 @@ Expectation can be narrowed to the specific stream.

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

expect(event_store).to have_published(an_event(OrderPlaced)).in_stream("Order$42")
```
Expand Down
14 changes: 7 additions & 7 deletions railseventstore.org/source/docs/subscribe.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ event_store.subscribe(handler, to: [OrderPlaced])
```

```ruby
event_store.publish_event(OrderPlaced.new)
event_store.publish(OrderPlaced.new)
# handler is called

event_store.publish_event(OrderPlaced.new)
event_store.publish(OrderPlaced.new)
# handler is called again
```

Expand Down Expand Up @@ -146,10 +146,10 @@ event_store.subscribe(SyncHandler, to: [OrderPlaced])
```

```ruby
event_store.publish_event(OrderPlaced.new(data: {customer_id: 2}))
event_store.publish(OrderPlaced.new(data: {customer_id: 2}))
# SyncHandler.new.call is invoked (instance A)

event_store.publish_event(OrderPlaced.new(data: {customer_id: 3}))
event_store.publish(OrderPlaced.new(data: {customer_id: 3}))
# SyncHandler.new.call is invoked (instance B)
```

Expand All @@ -160,7 +160,7 @@ Those handlers are executed immediately after events are stored in the DB.
```ruby
ActiveRecord::Base.transction do
order = Order.new(...).save!
event_store.publish_event(
event_store.publish(
OrderPlaced.new(data:{order_id: order.id}),
stream_name: "Order-#{order.id}"
)
Expand Down Expand Up @@ -329,7 +329,7 @@ Those async handlers are scheduled immediately after events are stored in the DB
```ruby
ActiveRecord::Base.transction do
order = Order.new(...).save!
event_store.publish_event(
event_store.publish(
OrderPlaced.new(data:{order_id: order.id}),
stream_name: "Order-#{order.id}"
)
Expand Down Expand Up @@ -378,7 +378,7 @@ event_store.subscribe(SendOrderEmail, to: [OrderPlaced])
```ruby
ActiveRecord::Base.transction do
order = Order.new(...).save!
event_store.publish_event(
event_store.publish(
OrderPlaced.new(data:{order_id: order.id}),
stream_name: "Order-#{order.id}"
)
Expand Down
2 changes: 1 addition & 1 deletion railseventstore.org/source/docs/without_rails.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ event_store = RubyEventStore::Client.new(
repository: RailsEventStoreActiveRecord::EventRepository.new
)

event_store.publish_event(OrderPlaced.new(data: {
event_store.publish(OrderPlaced.new(data: {
order_id: 1,
customer_id: 47271,
amount: BigDecimal.new("20.00"),
Expand Down

0 comments on commit e424b14

Please sign in to comment.