Class: Euston::AggregateCommandMap

Inherits:
Object
  • Object
show all
Defined in:
lib/euston/aggregate_command_map.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.mapObject (readonly)

for tests



45
46
47
# File 'lib/euston/aggregate_command_map.rb', line 45

def map
  @map
end

Class Method Details

.deliver_command(headers, command, logger = Euston::NullLogger.instance) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/euston/aggregate_command_map.rb', line 63

def deliver_command(headers, command, logger = Euston::NullLogger.instance)
  args = [headers, command]
  query = {:kind => :construct, :type => headers.type}
  if (entry = @map.find_entry_with_mapping_match( query ))
    aggregate = load_aggregate(entry, *args) || create_aggregate(entry, *args)
  else
    query[:kind] = :consume
    entry = @map.find_entry_with_mapping_match( query )
    return unless entry
    aggregate = load_aggregate(entry, *args)
  end

  raise Euston::Errors::AggregateNotFoundError if aggregate.nil?

  aggregate.log = logger
  aggregate.consume_command( headers, command )
end

.map_command_as_aggregate_constructor(type, command, identifier, to_i = []) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/euston/aggregate_command_map.rb', line 47

def map_command_as_aggregate_constructor(type, command, identifier, to_i = [])
  @map ||= AggregateMap.new
  mapping = { :kind => :construct, :type => command, :identifier => identifier, :to_i => to_i }
  if ( aggregate_entry = @map.find_entry_by_type(type) )
    aggregate_entry[:mappings].push_if_unique(mapping, command)
  else
    @map << AggregateEntry.new.merge!( :type => type, :mappings => MappingMap.new.push(mapping) )
  end
end

.map_command_as_aggregate_method(type, command, identifier, to_i = []) ⇒ Object



57
58
59
60
61
# File 'lib/euston/aggregate_command_map.rb', line 57

def map_command_as_aggregate_method(type, command, identifier, to_i = [])
  mapping = { :kind => :consume, :type => command, :identifier => identifier, :to_i => to_i }
  aggregate_entry =  @map.find_entry_by_type(type)
  aggregate_entry[:mappings].push_if_unique(mapping, command)
end