Sha256: 0ba2097499143e4d7fbc07dfa7f90c44553ca6d9849abbb2e2720ffe56ec766c

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'rlyeh/environment'
require 'rlyeh/filters'
require 'rlyeh/sendable'

module Rlyeh
  class Connection < EventMachine::Connection
    include EventMachine::Protocols::LineText2
    include Rlyeh::Sendable

    attr_reader :server, :app_class, :options
    attr_reader :app, :session

    def initialize(server, app_class, options)
      @server = server
      @app_class = app_class
      @options = options
      set_delimiter "\r\n"
    end

    def post_init
      @app = app_class.new nil, @options
    end

    def unbind
      @server.unbind self
    end

    def receive_line(data)
      env = Rlyeh::Environment.new
      env.data = data
      env.server = @server
      env.connection = self
      env.settings = @app_class.settings

      catch :halt do
        @app.call env
      end
    end

    def attached(session)
      @session = session
    end

    def detached(session)
      @session = nil
    end

    def attached?
      !!@session
    end

    include Rlyeh::Filters
    define_filters :attached, :detached
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rlyeh-0.0.2 lib/rlyeh/connection.rb