Class: Blather::Stream::Features

Inherits:
Object
  • Object
show all
Defined in:
lib/blather/stream/features.rb

Overview

:nodoc:

Direct Known Subclasses

Resource, SASL, Session, TLS

Constant Summary collapse

@@features =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, succeed, fail) ⇒ Features

Returns a new instance of Features.



14
15
16
17
18
# File 'lib/blather/stream/features.rb', line 14

def initialize(stream, succeed, fail)
  @stream = stream
  @succeed = succeed
  @fail = fail
end

Class Method Details

.from_namespace(ns) ⇒ Object



10
11
12
# File 'lib/blather/stream/features.rb', line 10

def self.from_namespace(ns)
  @@features[ns]
end

.register(ns) ⇒ Object



6
7
8
# File 'lib/blather/stream/features.rb', line 6

def self.register(ns)
  @@features[ns] = self
end

Instance Method Details

#fail!(msg) ⇒ Object



47
48
49
# File 'lib/blather/stream/features.rb', line 47

def fail!(msg)
  @fail.call msg
end

#next!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/blather/stream/features.rb', line 29

def next!
  @idx = @idx ? @idx+1 : 0
  if stanza = @features.children[@idx]
    if stanza.namespaces['xmlns'] && (klass = self.class.from_namespace(stanza.namespaces['xmlns']))
      @feature = klass.new @stream, proc { next! }, @fail
      @feature.receive_data stanza
    else
      next!
    end
  else
    succeed!
  end
end

#receive_data(stanza) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/blather/stream/features.rb', line 20

def receive_data(stanza)
  if @feature
    @feature.receive_data stanza
  else
    @features ||= stanza
    next!
  end
end

#succeed!Object



43
44
45
# File 'lib/blather/stream/features.rb', line 43

def succeed!
  @succeed.call
end