Class: TorqueBox::Messaging::ProcessorMiddleware::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/messaging/processor_middleware/chain.rb

Instance Method Summary collapse

Instance Method Details

#append(klass, *args) ⇒ Object Also known as: add



28
29
30
31
# File 'lib/torquebox/messaging/processor_middleware/chain.rb', line 28

def append(klass, *args)
  chain << MWare.new(klass, args) unless locate(klass)
  self
end

#inspectObject



41
42
43
# File 'lib/torquebox/messaging/processor_middleware/chain.rb', line 41

def inspect
  chain.map(&:klass).inspect
end

#invoke(session, message, processor) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/torquebox/messaging/processor_middleware/chain.rb', line 45

def invoke(session, message, processor)
  realized_chain = realize
  walker = lambda do
    mware = realized_chain.shift
    if mware
      mware.call(session, message, &walker)
    else
      processor.process!(message)
    end
  end
  walker.call
end

#prepend(klass, *args) ⇒ Object



23
24
25
26
# File 'lib/torquebox/messaging/processor_middleware/chain.rb', line 23

def prepend(klass, *args)
  chain.unshift(MWare.new(klass, args)) unless locate(klass)
  self
end

#remove(klass) ⇒ Object



35
36
37
38
39
# File 'lib/torquebox/messaging/processor_middleware/chain.rb', line 35

def remove(klass)
  loc = locate(klass)
  chain.delete_at(loc) if loc
  self
end