Sha256: de94b86c46bdc5b48edda1ddae6aef0140ca4ddde59199ebec3bdb0f545505b9

Contents?: true

Size: 1.17 KB

Versions: 27

Compression:

Stored size: 1.17 KB

Contents

# encoding: UTF-8

module Vines
  class Stream

    # The base class of Stream state machines. States know how to process XML
    # nodes and advance to their next valid state or fail the stream.
    class State
      include Nokogiri::XML
      include Vines::Log

      attr_accessor :stream

      BODY   = 'body'.freeze
      STREAM = 'stream'.freeze

      def initialize(stream, success=nil)
        @stream, @success = stream, success
      end

      def node(node)
        raise 'subclass must implement'
      end

      def ==(state)
        self.class == state.class
      end

      def eql?(state)
        state.is_a?(State) && self == state
      end

      def hash
        self.class.hash
      end

      private

      def advance
        stream.advance(@success.new(stream))
      end

      def stream?(node)
        node.name == STREAM && namespace(node) == NAMESPACES[:stream]
      end

      def body?(node)
        node.name == BODY && namespace(node) == NAMESPACES[:http_bind]
      end

      def namespace(node)
        node.namespace ? node.namespace.href : nil
      end

      def to_stanza(node)
        Stanza.from_node(node, stream)
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
lygneo-vines-0.1.5 lib/vines/stream/state.rb
lygneo-vines-0.1.1 lib/vines/stream/state.rb
diaspora-vines-0.1.26 lib/vines/stream/state.rb
diaspora-vines-0.1.25 lib/vines/stream/state.rb
diaspora-vines-0.1.24 lib/vines/stream/state.rb
vines-0.4.10 lib/vines/stream/state.rb
diaspora-vines-0.1.22 lib/vines/stream/state.rb
diaspora-vines-0.1.21 lib/vines/stream/state.rb
diaspora-vines-0.1.2 lib/vines/stream/state.rb
vines-0.4.9 lib/vines/stream/state.rb
vines-0.4.8 lib/vines/stream/state.rb
vines-0.4.7 lib/vines/stream/state.rb
vines-0.4.6 lib/vines/stream/state.rb
vinesmod-0.4.5.2 lib/vines/stream/state.rb
vinesmod-0.4.5 lib/vines/stream/state.rb
vines-0.4.5 lib/vines/stream/state.rb
vines-0.4.4 lib/vines/stream/state.rb
vines-0.4.3 lib/vines/stream/state.rb
vines-0.4.2 lib/vines/stream/state.rb
vines-0.4.1 lib/vines/stream/state.rb