Module: Sandthorn::AggregateRoot::Base

Included in:
Sandthorn::AggregateRoot
Defined in:
lib/sandthorn/aggregate_root_base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aggregate_current_event_versionObject (readonly) Also known as: aggregate_version

Returns the value of attribute aggregate_current_event_version.



7
8
9
# File 'lib/sandthorn/aggregate_root_base.rb', line 7

def aggregate_current_event_version
  @aggregate_current_event_version
end

#aggregate_eventsObject (readonly)

Returns the value of attribute aggregate_events.



6
7
8
# File 'lib/sandthorn/aggregate_root_base.rb', line 6

def aggregate_events
  @aggregate_events
end

#aggregate_idObject (readonly) Also known as: id

Returns the value of attribute aggregate_id.



5
6
7
# File 'lib/sandthorn/aggregate_root_base.rb', line 5

def aggregate_id
  @aggregate_id
end

#aggregate_originating_versionObject (readonly)

Returns the value of attribute aggregate_originating_version.



8
9
10
# File 'lib/sandthorn/aggregate_root_base.rb', line 8

def aggregate_originating_version
  @aggregate_originating_version
end

#aggregate_trace_informationObject (readonly)

Returns the value of attribute aggregate_trace_information.



9
10
11
# File 'lib/sandthorn/aggregate_root_base.rb', line 9

def aggregate_trace_information
  @aggregate_trace_information
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  other.respond_to?(:aggregate_id) && aggregate_id == other.aggregate_id
end

#aggregate_base_initializeObject



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

def aggregate_base_initialize
  @aggregate_current_event_version = 0
  @aggregate_originating_version = 0
  @aggregate_events = []
end

#aggregate_trace(args) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



45
46
47
48
49
# File 'lib/sandthorn/aggregate_root_base.rb', line 45

def aggregate_trace args
  @aggregate_trace_information = args
  yield self if block_given?
  @aggregate_trace_information = nil
end

#commitObject Also known as: record_event



51
52
53
54
# File 'lib/sandthorn/aggregate_root_base.rb', line 51

def commit
  event_name = caller_locations(1,1)[0].label.gsub(/block ?(.*) in /, "")
  commit_with_event_name(event_name)
end

#default_attributesObject



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

def default_attributes
  #NOOP
end

#saveObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sandthorn/aggregate_root_base.rb', line 21

def save
  if aggregate_events.any?
    Sandthorn.save_events(
      aggregate_events,
      aggregate_id,
      self.class
    )
    @aggregate_events = []
    @aggregate_originating_version = @aggregate_current_event_version
  end

  Sandthorn.save_snapshot self if self.class.snapshot

  self
end

#unsaved_events?Boolean

Returns:

  • (Boolean)


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

def unsaved_events?
  aggregate_events.any?
end