Module: Sandthorn

Extended by:
Forwardable
Defined in:
lib/sandthorn.rb,
lib/sandthorn/errors.rb,
lib/sandthorn/version.rb,
lib/sandthorn/event_stores.rb,
lib/sandthorn/aggregate_root.rb,
lib/sandthorn/snapshot_store.rb,
lib/sandthorn/bounded_context.rb,
lib/sandthorn/event_inspector.rb,
lib/sandthorn/aggregate_root_base.rb,
lib/sandthorn/aggregate_root_marshal.rb

Defined Under Namespace

Modules: AggregateRoot, BoundedContext, Errors, EventInspector Classes: Configuration, EventStores, SnapshotStore

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.all(aggregate_type) ⇒ Object



40
41
42
# File 'lib/sandthorn.rb', line 40

def all aggregate_type
  event_store_for(aggregate_type).all(aggregate_type)
end

.configurationObject



28
29
30
# File 'lib/sandthorn.rb', line 28

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



24
25
26
# File 'lib/sandthorn.rb', line 24

def configure
  yield(configuration) if block_given?
end

.default_event_storeObject



16
17
18
# File 'lib/sandthorn.rb', line 16

def default_event_store
  event_stores.default_store
end

.default_event_store=(store) ⇒ Object



20
21
22
# File 'lib/sandthorn.rb', line 20

def default_event_store=(store)
  event_stores.default_store = store
end

.find(aggregate_id, aggregate_type, after_aggregate_version = 0) ⇒ Object



44
45
46
# File 'lib/sandthorn.rb', line 44

def find aggregate_id, aggregate_type, after_aggregate_version = 0
  event_store_for(aggregate_type).find(aggregate_id, aggregate_type, after_aggregate_version)
end

.find_event_store(name) ⇒ Object



57
58
59
# File 'lib/sandthorn.rb', line 57

def find_event_store(name)
  event_stores.by_name(name)
end

.find_snapshot(aggregate_id) ⇒ Object



53
54
55
# File 'lib/sandthorn.rb', line 53

def find_snapshot aggregate_id
  return snapshot_store.find aggregate_id
end

.generate_aggregate_idObject



32
33
34
# File 'lib/sandthorn.rb', line 32

def generate_aggregate_id
  SecureRandom.uuid
end

.save_events(aggregate_events, aggregate_id, aggregate_type) ⇒ Object



36
37
38
# File 'lib/sandthorn.rb', line 36

def save_events aggregate_events, aggregate_id, aggregate_type
  event_store_for(aggregate_type).save_events aggregate_events, aggregate_id, *aggregate_type
end

.save_snapshot(aggregate) ⇒ Object



48
49
50
51
# File 'lib/sandthorn.rb', line 48

def save_snapshot aggregate
  raise Errors::SnapshotError, "Can't take snapshot on object with unsaved events" if aggregate.unsaved_events?
  snapshot_store.save aggregate.aggregate_id, aggregate
end