Class: EventSource::EntityRepository
- Inherits:
-
Object
- Object
- EventSource::EntityRepository
show all
- Extended by:
- MemoizeInstance
- Defined in:
- lib/event_source/entity_repository.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
create, current, default_args
Constructor Details
Returns a new instance of EntityRepository.
22
23
24
25
|
# File 'lib/event_source/entity_repository.rb', line 22
def initialize(event_repo = nil)
@entities = Set.new
@event_repo = event_repo
end
|
Instance Attribute Details
#entities ⇒ Object
Returns the value of attribute entities.
12
13
14
|
# File 'lib/event_source/entity_repository.rb', line 12
def entities
@entities
end
|
Class Method Details
.transaction ⇒ Object
15
16
17
18
19
|
# File 'lib/event_source/entity_repository.rb', line 15
def transaction
self.current.clear
yield
self.current.commit
end
|
Instance Method Details
#add(entity) ⇒ Object
31
32
33
|
# File 'lib/event_source/entity_repository.rb', line 31
def add(entity)
@entities << entity
end
|
#clear ⇒ Object
27
28
29
|
# File 'lib/event_source/entity_repository.rb', line 27
def clear
@entities.clear
end
|
#commit ⇒ Object
35
36
37
38
39
|
# File 'lib/event_source/entity_repository.rb', line 35
def commit
@entities.each {|e| e.save}
clear
end
|
#find(type, uid) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# 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
|