module EntityStore::Entity
Attributes
id[RW]
Public Class Methods
included(klass)
click to toggle source
# File lib/entity_store/entity.rb, line 5 def self.included(klass) klass.class_eval do include HashSerialization include Attributes version_incremented_event_class = "#{self.name}VersionIncremented".split('::').inject(Object) {|obj, name| obj.const_defined?(name) ? obj.const_get(name) : obj.const_set(name, Class.new) } version_incremented_event_class.class_eval %Q" include ::EntityStore::Event attr_accessor :version def apply(entity) # nothing to do as signal event end " end end
Public Instance Methods
apply_event(event)
click to toggle source
# File lib/entity_store/entity.rb, line 65 def apply_event(event) event.apply(self) end
clear_pending_events()
click to toggle source
# File lib/entity_store/entity.rb, line 56 def clear_pending_events @pending_events = [] end
generate_version_incremented_event()
click to toggle source
# File lib/entity_store/entity.rb, line 47 def generate_version_incremented_event event_class= "#{self.class.name}VersionIncremented".split('::').inject(Object) {|obj, name| obj.const_get(name) } event_class.new(:entity_id => id, :version => version) end
inspect()
click to toggle source
# File lib/entity_store/entity.rb, line 69 def inspect "<#{self.class.name} #{id} #{self.attributes.inspect}>" end
pending_events()
click to toggle source
# File lib/entity_store/entity.rb, line 52 def pending_events @pending_events ||= [] end
record_event(event)
click to toggle source
# File lib/entity_store/entity.rb, line 60 def record_event(event) apply_event(event) pending_events<<event end
snapshot_due?()
click to toggle source
# File lib/entity_store/entity.rb, line 39 def snapshot_due? if version % Config.snapshot_threshold == 0 true else @_snapshot_version and (version - @_snapshot_version) >= Config.snapshot_threshold end end
type()
click to toggle source
# File lib/entity_store/entity.rb, line 26 def type self.class.name end
version()
click to toggle source
# File lib/entity_store/entity.rb, line 30 def version @_version ||= 1 end
version=(value)
click to toggle source
# File lib/entity_store/entity.rb, line 34 def version=(value) @_snapshot_version = value unless @_snapshot_version @_version = value end