class EventSource::EntityRepository
Attributes
entities[R]
Public Class Methods
new(event_repo = nil)
click to toggle source
# File lib/event_source/entity_repository.rb, line 22 def initialize(event_repo = nil) @entities = Set.new @event_repo = event_repo end
transaction() { || ... }
click to toggle source
# File lib/event_source/entity_repository.rb, line 15 def transaction self.current.clear yield self.current.commit end
Private Class Methods
default_args()
click to toggle source
# File lib/event_source/entity_repository.rb, line 59 def self.default_args [EventSource::EventRepository.current] end
Public Instance Methods
add(entity)
click to toggle source
# File lib/event_source/entity_repository.rb, line 31 def add(entity) @entities << entity end
clear()
click to toggle source
# File lib/event_source/entity_repository.rb, line 27 def clear @entities.clear end
commit()
click to toggle source
# File lib/event_source/entity_repository.rb, line 35 def commit # TODO: gather all events of all entities, maintain order and save in batch @entities.each {|e| e.save} clear end
find(type, uid)
click to toggle source
# File lib/event_source/entity_repository.rb, line 41 def find(type, uid) entity = @entities.select {|e| e.uid == uid}[0] return entity if entity events = @event_repo.get_events(type, uid) entity_class = type.to_s.camelize.constantize if events.count > 0 entity = entity_class.rebuild(uid, events) else entity = entity_class.create(uid) end entity end