Mongrel2::Config::Host::

DSLMethods

module

DSL methods for the Server context besides those automatically-generated from its columns.

Public Instance Methods

anchor
directory( base, index_file='index.html', default_ctype='text/plain', opts={} )

Create a new Mongrel2::Config::Directory object for the specified base and return it.

# File lib/mongrel2/config/host.rb, line 66
def directory( base, index_file='index.html', default_ctype='text/plain', opts={} )
        opts.merge!( :base => base, :index_file => index_file, :default_ctype => default_ctype )
        return Mongrel2::Config::Directory.create( opts )
end
anchor
handler( send_spec, send_ident, recv_spec=nil, recv_ident='', options={} )

Create a new Mongrel2::Config::Handler object with the specified send_spec, send_ident, recv_spec, recv_ident, and options and return it.

# File lib/mongrel2/config/host.rb, line 81
def handler( send_spec, send_ident, recv_spec=nil, recv_ident='', options={} )
        # Shift the opts hash over if the other optional args were omitted
        if recv_spec.is_a?( Hash )
                options = recv_spec
                recv_spec = nil
        elsif recv_ident.is_a?( Hash )
                options = recv_ident
                recv_ident = ''
        end

        # Default to one port below the request spec
        unless recv_spec
                port = send_spec[ /:(\d+)$/, 1 ] or
                        "Can't guess default port for a send_spec without one (%p)" % [ send_spec ]
                recv_spec = URI( send_spec )
                recv_spec.port = port.to_i - 1
        end

        options.merge!(
                :send_spec  => send_spec.to_s,
                :send_ident => send_ident,
                :recv_spec  => recv_spec.to_s,
                :recv_ident => recv_ident
        )

        existing = Mongrel2::Config::Handler.filter( :send_ident => send_ident )
        unless existing.select( :id ).empty?
                self.log.debug "Dropping existing %p handler." % [ send_ident ]
                existing.delete
        end

        self.log.debug "Creating handler with options: %p" % [ options ]
        return Mongrel2::Config::Handler.create( options )
end
anchor
proxy( addr, port=80 )

Create a new Mongrel2::Config::Proxy object for the specified addr and port and return it.

# File lib/mongrel2/config/host.rb, line 74
def proxy( addr, port=80 )
        return Mongrel2::Config::Proxy.create( :addr => addr, :port => port )
end
anchor
route( path, target, opts={} )

Add a Mongrel2::Config::Route to the Host object.

# File lib/mongrel2/config/host.rb, line 49
def route( path, target, opts={} )
        self.target.save
        self.log.debug "Route %s -> %p [%p]" % [ path, target, opts ]

        args = { :path => path, :target => target }
        args.merge!( opts )
        route = Mongrel2::Config::Route.new( args )

        self.target.add_route( route )
end