### Home Classes Methods

### In Files

- lib/cool.io/dsl.rb

### Namespace

- CLASS Coolio::DSL::ConnectionBuilder

### Methods

- #[]
- #connect
- #connection
- #run
- #server

### Class/Module Index

Quicksearch

- Coolio
- Coolio::AsyncWatcher
- Coolio::Connections
- Coolio::DNSResolver
- Coolio::DNSResolver::Timeout
- Coolio::DSL
- Coolio::DSL::ConnectionBuilder
- Coolio::IO
- Coolio::IO::Watcher
- Coolio::IOWatcher
- Coolio::Listener
- Coolio::Loop
- Coolio::Meta
- Coolio::Server
- Coolio::Socket
- Coolio::Socket::Connector
- Coolio::TCPListener
- Coolio::TCPServer
- Coolio::TCPSocket
- Coolio::TCPSocket::TCPConnectResolver
- Coolio::TCPSocket::TCPConnectSocket
- Coolio::TimerWatcher
- Coolio::UNIXListener
- Coolio::UNIXServer
- Coolio::UNIXSocket
- Cool
- Cool::Coolness
- Cool::IOThunk
- Object
- Thread

No matching classes.

# Coolio::DSL

A DSL for defining Cool.io connection types and servers

### Public Instance Methods

[](connection_name) click to toggle source

Look up a connection class by its name

    # File lib/cool.io/dsl.rb, line 70
    def [](connection_name)
      class_name = connection_name.to_s.split('_').map { |s| s.capitalize }.join

      begin
        Coolio::Connections.const_get class_name
      rescue NameError
        raise NameError, "No connection type registered for #{connection_name.inspect}"
      end
    end

connect(host, port, connection_name = nil, *initializer_args, &block) click to toggle source

Connect to the given host and port using the given connection class

    # File lib/cool.io/dsl.rb, line 22
    def connect(host, port, connection_name = nil, *initializer_args, &block)
      if block_given?
        initializer_args.unshift connection_name if connection_name

        klass = Class.new Cool.io::TCPSocket
        connection_builder = ConnectionBuilder.new klass
        connection_builder.instance_eval(&block)
      else
        raise ArgumentError, "no connection name or block given" unless connection_name
        klass = self[connection_name]
      end

      client = klass.connect host, port, *initializer_args
      client.attach Cool.io::Loop.default
      client
    end

connection(name, &block) click to toggle source

Create a new Cool.io::TCPSocket class

    # File lib/cool.io/dsl.rb, line 58
    def connection(name, &block)
      # Camelize class name
      class_name = name.to_s.split('_').map { |s| s.capitalize }.join

      connection = Class.new Cool.io::TCPSocket
      connection_builder = ConnectionBuilder.new connection
      connection_builder.instance_eval(&block)

      Coolio::Connections.const_set class_name, connection
    end

run() click to toggle source

Run the default Cool.io event loop

    # File lib/cool.io/dsl.rb, line 17
    def run
      Cool.io::Loop.default.run
    end

server(host, port, connection_name = nil, *initializer_args, &block) click to toggle source

Create a new Cool.io::TCPServer

    # File lib/cool.io/dsl.rb, line 40
    def server(host, port, connection_name = nil, *initializer_args, &block)
      if block_given?
        initializer_args.unshift connection_name if connection_name

        klass = Class.new Cool.io::TCPSocket
        connection_builder = ConnectionBuilder.new klass
        connection_builder.instance_eval(&block)
      else
        raise ArgumentError, "no connection name or block given" unless connection_name
        klass = self[connection_name]
      end

      server = Cool.io::TCPServer.new host, port, klass, *initializer_args
      server.attach Cool.io::Loop.default
      server
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.