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

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) append(klass, *args)



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

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

- (Object) chain



61
62
63
# File 'messaging/lib/torquebox/messaging/processor_middleware/chain.rb', line 61

def chain
  @chain ||= []
end

- (Object) inspect



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

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

- (Object) invoke(session, message, processor)



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

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

- (Object) locate(klass)



65
66
67
# File 'messaging/lib/torquebox/messaging/processor_middleware/chain.rb', line 65

def locate(klass)
  chain.index { |m| m.klass == klass }
end

- (Object) prepend(klass, *args)



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

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

- (Object) realize



69
70
71
# File 'messaging/lib/torquebox/messaging/processor_middleware/chain.rb', line 69

def realize
  chain.map(&:instance)
end

- (Object) remove(klass)



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

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