Module: AggregateRoot::AggregateMethods

Defined in:
lib/aggregate_root.rb

Constant Summary collapse

UNMARSHALED_VARIABLES =
[:@version, :@unpublished_events]

Instance Method Summary collapse

Instance Method Details

#apply(*events) ⇒ Object



45
46
47
48
49
50
# File 'lib/aggregate_root.rb', line 45

def apply(*events)
  events.each do |event|
    apply_strategy.(self, event)
    @unpublished_events << event
  end
end

#marshal_dumpObject



67
68
69
70
71
72
# File 'lib/aggregate_root.rb', line 67

def marshal_dump
  instance_variables.reject{|m| UNMARSHALED_VARIABLES.include? m}.inject({}) do |vars, attr|
    vars[attr] = instance_variable_get(attr)
    vars
  end
end

#marshal_load(vars) ⇒ Object



74
75
76
77
78
# File 'lib/aggregate_root.rb', line 74

def marshal_load(vars)
  vars.each do |attr, value|
    instance_variable_set(attr, value) unless UNMARSHALED_VARIABLES.include?(attr)
  end
end

#unpublished_eventsObject



61
62
63
# File 'lib/aggregate_root.rb', line 61

def unpublished_events
  @unpublished_events.each
end

#versionObject



52
53
54
# File 'lib/aggregate_root.rb', line 52

def version
  @version
end

#version=(value) ⇒ Object



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

def version=(value)
  @unpublished_events = []
  @version = value
end