Skip to content

Commit

Permalink
Merge 2df77eb into 1998996
Browse files Browse the repository at this point in the history
  • Loading branch information
hallgren committed Jun 29, 2018
2 parents 1998996 + 2df77eb commit d9e7687
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,3 +19,4 @@ Gemfile.lock
_yardoc
doc/
.idea
Dockerfile
17 changes: 13 additions & 4 deletions README.md
Expand Up @@ -258,9 +258,6 @@ If there is a lot of events saved to an aggregate it can take some time to reloa

There is one global snapshot store where all snapshots are stored independent on aggregate_type. To enable snapshot on a aggregate_type the Class has to be added to the `snapshot_types` Array when configuring Sandthorn. The aggregate will now be stored to the snapshot_store on every `.save` and when using `.find` it will look for a snapshot of the requested aggregate.

Currently its only possible to store the snapshots in memory, so be careful not draining your applications memory space.


```ruby

class Board
Expand All @@ -272,7 +269,7 @@ Sandthorn.configure do |c|
end
```

Its also possible to take manual snapshots without enabling snapshots on the aggregate_type.
Its possible to take manual snapshots without enabling snapshots on the aggregate_type.

```ruby
board = Board.new
Expand All @@ -285,6 +282,18 @@ Sandthorn.save_snapshot board
snapshot = Sandthorn.find_snapshot board.aggregate_id
```

### External snapshot store

Currently there is no external snapshot stores available but this is how `Sandthorn` should be configured with one when there is.

```ruby
Sandthorn.configure do |conf|
conf.snapshot_store = <snapshot_store_driver>
end
```

**Currently its only possible to store the snapshots in the application memory (be careful not draining your application memory space).**

## Bounded Context

A bounded context is a system divider that split large systems into smaller parts. [Bounded Context by Martin Fowler](http://martinfowler.com/bliki/BoundedContext.html)
Expand Down
12 changes: 8 additions & 4 deletions lib/sandthorn.rb
Expand Up @@ -2,7 +2,7 @@
require "sandthorn/errors"
require "sandthorn/aggregate_root"
require "sandthorn/event_stores"
require "sandthorn/snapshot_store"
require "sandthorn/application_snapshot_store"
require 'yaml'
require 'securerandom'

Expand Down Expand Up @@ -83,16 +83,20 @@ def event_stores
@event_stores ||= EventStores.new
end

def event_store=(store)
@event_stores = EventStores.new(store)
def event_store=(event_store)
@event_stores = EventStores.new(event_store)
end

def map_types= data
@event_stores.map_types data
end

def snapshot_store
@snapshot_store ||= SnapshotStore.new
@snapshot_store ||= ApplicationSnapshotStore.new
end

def snapshot_store=(snapshot_store)
@snapshot_store = snapshot_store
end

def snapshot_types= aggregate_types
Expand Down
17 changes: 17 additions & 0 deletions lib/sandthorn/application_snapshot_store.rb
@@ -0,0 +1,17 @@
module Sandthorn
class ApplicationSnapshotStore
def initialize
@store = Hash.new
end

attr_reader :store

def save aggregate_id, aggregate
@store[aggregate_id] = aggregate
end

def find aggregate_id
@store[aggregate_id]
end
end
end
17 changes: 0 additions & 17 deletions lib/sandthorn/snapshot_store.rb

This file was deleted.

0 comments on commit d9e7687

Please sign in to comment.