Sha256: 3d35d62df65f06c68854146c377819e6036c35ca97c390f6fbedb8345ccc776e

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

module Faye
  module Extensible
    
    def add_extension(extension)
      @extensions ||= []
      @extensions << extension
      extension.added if extension.respond_to?(:added)
    end
    
    def remove_extension(extension)
      return unless @extensions
      @extensions.delete_if do |ext|
        if ext == extension
          extension.removed if extension.respond_to?(:removed)
          true
        else
          false
        end
      end
    end
    
    def pipe_through_extensions(stage, message, &callback)
      return callback.call(message) unless @extensions
      extensions = @extensions.dup
      
      pipe = lambda do |message|
        if !message
          callback.call(message)
        else
          extension = extensions.shift
          if (!extension)
            callback.call(message)
          else
            if extension.respond_to?(stage)
              extension.__send__(stage, message, pipe)
            else
              pipe.call(message)
            end
          end
        end
      end
      pipe.call(message)
    end
    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
faye-0.5.5 lib/faye/protocol/extensible.rb
faye-0.5.4 lib/faye/protocol/extensible.rb
faye-0.5.3 lib/faye/protocol/extensible.rb
faye-0.5.2 lib/faye/protocol/extensible.rb
faye-0.5.1 lib/faye/protocol/extensible.rb
faye-0.5.0 lib/faye/protocol/extensible.rb