Class: RubyEventStore::Mappers::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/mappers/pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*transformations, to_domain_event: Transformation::DomainEvent.new) ⇒ Pipeline

Returns a new instance of Pipeline.



6
7
8
# File 'lib/ruby_event_store/mappers/pipeline.rb', line 6

def initialize(*transformations, to_domain_event: Transformation::DomainEvent.new)
  @transformations = [to_domain_event, transformations].flatten.freeze
end

Instance Attribute Details

#transformationsObject (readonly)

Returns the value of attribute transformations.



18
19
20
# File 'lib/ruby_event_store/mappers/pipeline.rb', line 18

def transformations
  @transformations
end

Instance Method Details

#dump(event) ⇒ Object



10
11
12
# File 'lib/ruby_event_store/mappers/pipeline.rb', line 10

def dump(event)
  transformations.reduce(event) { |item, transform| transform.dump(item) }
end

#load(record) ⇒ Object



14
15
16
# File 'lib/ruby_event_store/mappers/pipeline.rb', line 14

def load(record)
  transformations.reverse.reduce(record) { |item, transform| transform.load(item) }
end