Module: Euston::Projections::MongoProjection::InstanceMethods

Defined in:
lib/euston-projections/mongo_projection.rb

Instance Method Summary collapse

Instance Method Details

#act_as(role) ⇒ Object



35
36
37
# File 'lib/euston-projections/mongo_projection.rb', line 35

def act_as(role)
  role.new(self)
end

#add_to_history(message_id) ⇒ Object



18
19
20
21
# File 'lib/euston-projections/mongo_projection.rb', line 18

def add_to_history message_id
  return if already_processed_message? message_id
  historical_messages << HistoricalMessage.new(message_id: message_id)
end

#already_processed_message?(*message_ids) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/euston-projections/mongo_projection.rb', line 23

def already_processed_message? *message_ids
  (processed_message_ids & message_ids).size == message_ids.size
end

#processed_message_idsObject



27
28
29
# File 'lib/euston-projections/mongo_projection.rb', line 27

def processed_message_ids
  historical_messages.map { |m| m.message_id }
end

#prune_history_older_than(time) ⇒ Object



31
32
33
# File 'lib/euston-projections/mongo_projection.rb', line 31

def prune_history_older_than time
  historical_messages.reject! { |m| m.timestamp < time }
end