Class: SandthornSequelProjection::Projection
- Inherits:
-
Object
- Object
- SandthornSequelProjection::Projection
- Extended by:
- Forwardable
- Includes:
- SimpleMigrator::Migratable
- Defined in:
- lib/sandthorn_sequel_projection/projection.rb
Class Attribute Summary collapse
-
.event_handlers ⇒ Object
Returns the value of attribute event_handlers.
-
.event_store_name ⇒ Object
readonly
Returns the value of attribute event_store_name.
Instance Attribute Summary collapse
-
#db_connection ⇒ Object
readonly
Returns the value of attribute db_connection.
-
#event_handlers ⇒ Object
readonly
Returns the value of attribute event_handlers.
-
#tracker ⇒ Object
readonly
Returns the value of attribute tracker.
Class Method Summary collapse
- .define_event_handlers {|@event_handlers| ... } ⇒ Object
- .event_store(event_store = nil) ⇒ Object
- .find_event_store ⇒ Object
- .identifier ⇒ Object
Instance Method Summary collapse
-
#initialize(db_connection = nil) ⇒ Projection
constructor
A new instance of Projection.
- #migrator ⇒ Object
- #update! ⇒ Object
Constructor Details
#initialize(db_connection = nil) ⇒ Projection
Returns a new instance of Projection.
13 14 15 16 17 18 19 20 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 13 def initialize(db_connection = nil) @db_connection = db_connection || SandthornSequelProjection.configuration.db_connection @tracker = ProcessedEventsTracker.new( identifier: identifier, db_connection: @db_connection, event_store: event_store) @event_handlers = self.class.event_handlers end |
Class Attribute Details
.event_handlers ⇒ Object
Returns the value of attribute event_handlers.
48 49 50 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 48 def event_handlers @event_handlers end |
.event_store_name ⇒ Object (readonly)
Returns the value of attribute event_store_name.
33 34 35 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 33 def event_store_name @event_store_name end |
Instance Attribute Details
#db_connection ⇒ Object (readonly)
Returns the value of attribute db_connection.
11 12 13 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 11 def db_connection @db_connection end |
#event_handlers ⇒ Object (readonly)
Returns the value of attribute event_handlers.
11 12 13 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 11 def event_handlers @event_handlers end |
#tracker ⇒ Object (readonly)
Returns the value of attribute tracker.
11 12 13 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 11 def tracker @tracker end |
Class Method Details
.define_event_handlers {|@event_handlers| ... } ⇒ Object
50 51 52 53 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 50 def define_event_handlers @event_handlers ||= EventHandlerCollection.new yield(@event_handlers) end |
.event_store(event_store = nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 35 def event_store(event_store = nil) if event_store @event_store_name = event_store else find_event_store end end |
.find_event_store ⇒ Object
43 44 45 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 43 def find_event_store SandthornSequelProjection.find_event_store(@event_store_name) end |
.identifier ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 55 def identifier self.name.gsub(/::/, '_'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |
Instance Method Details
#migrator ⇒ Object
28 29 30 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 28 def migrator SimpleMigrator.migrator(db_connection) end |
#update! ⇒ Object
22 23 24 25 26 |
# File 'lib/sandthorn_sequel_projection/projection.rb', line 22 def update! tracker.process_events do |batch| event_handlers.handle(self, batch) end end |