Class: RubyEventStore::Mappers::Transformation::Upcast::RecordUpcaster

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

Instance Method Summary collapse

Constructor Details

#initialize(upcast_map) ⇒ RecordUpcaster

Returns a new instance of RecordUpcaster.



8
9
10
# File 'lib/ruby_event_store/mappers/transformation/upcast.rb', line 8

def initialize(upcast_map)
  @upcast_map = upcast_map
end

Instance Method Details

#call(record) ⇒ Object



12
13
14
15
16
# File 'lib/ruby_event_store/mappers/transformation/upcast.rb', line 12

def call(record)
  identity = lambda { |r| r }
  new_record = @upcast_map.fetch(record.event_type, identity)[record]
  new_record.equal?(record) ? record : call(new_record)
end