Sha256: 0c359aa09509eb2e0416905a51dea1a82aec977a0ea4e54f136b818faab85b85

Contents?: true

Size: 1004 Bytes

Versions: 20

Compression:

Stored size: 1004 Bytes

Contents

module Blather # :nodoc:
class Stream # :nodoc:

  class Features # :nodoc:
    @@features = {}
    def self.register(ns)
      @@features[ns] = self
    end

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

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

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

    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

    def succeed!
      @succeed.call
    end

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

end #Stream
end #Blather

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
sprsquish-blather-0.4.2 lib/blather/stream/features.rb
sprsquish-blather-0.4.3 lib/blather/stream/features.rb
sprsquish-blather-0.4.4 lib/blather/stream/features.rb
blather-0.4.16 lib/blather/stream/features.rb
blather-0.4.15 lib/blather/stream/features.rb
shingara-blather-0.4.14 lib/blather/stream/features.rb
blather-0.4.14 lib/blather/stream/features.rb
blather-0.4.13 lib/blather/stream/features.rb
blather-0.4.12 lib/blather/stream/features.rb
blather-0.4.11 lib/blather/stream/features.rb
blather-0.4.10 lib/blather/stream/features.rb
shingara-blather-0.4.9 lib/blather/stream/features.rb
shingara-blather-0.4.8 lib/blather/stream/features.rb
blather-0.4.8 lib/blather/stream/features.rb
blather-0.4.7 lib/blather/stream/features.rb
blather-0.4.6 lib/blather/stream/features.rb
blather-0.4.5 lib/blather/stream/features.rb
blather-0.4.4 lib/blather/stream/features.rb
blather-0.4.3 lib/blather/stream/features.rb
blather-0.4.2 lib/blather/stream/features.rb