Module: Mongrel2::Config::Host::DSLMethods
- Defined in:
- lib/mongrel2/config/host.rb
Overview
DSL methods for the Server context besides those automatically-generated from its columns.
Instance Method Summary collapse
-
#directory(base, index_file = 'index.html', default_ctype = 'text/plain', opts = {}) ⇒ Object
Create a new Mongrel2::Config::Directory object for the specified
baseand return it. -
#handler(send_spec, send_ident, recv_spec = nil, recv_ident = '', options = {}) ⇒ Object
Create a new Mongrel2::Config::Handler object with the specified
send_spec,send_ident,recv_spec,recv_ident, andoptionsand return it. -
#proxy(addr, port = 80) ⇒ Object
Create a new Mongrel2::Config::Proxy object for the specified
addrandportand return it. -
#route(path, target, opts = {}) ⇒ Object
Add a Mongrel2::Config::Route to the Host object.
Instance Method Details
#directory(base, index_file = 'index.html', default_ctype = 'text/plain', opts = {}) ⇒ Object
Create a new Mongrel2::Config::Directory object for the specified base and return it.
67 68 69 70 |
# File 'lib/mongrel2/config/host.rb', line 67 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 |
#handler(send_spec, send_ident, recv_spec = nil, recv_ident = '', options = {}) ⇒ Object
Create a new Mongrel2::Config::Handler object with the specified send_spec, send_ident, recv_spec, recv_ident, and options and return it.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mongrel2/config/host.rb', line 82 def handler( send_spec, send_ident, recv_spec=nil, recv_ident='', ={} ) # Shift the opts hash over if the other optional args were omitted if recv_spec.is_a?( Hash ) = recv_spec recv_spec = nil elsif recv_ident.is_a?( Hash ) = 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 .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" % [ ] return Mongrel2::Config::Handler.create( ) end |
#proxy(addr, port = 80) ⇒ Object
Create a new Mongrel2::Config::Proxy object for the specified addr and port and return it.
75 76 77 |
# File 'lib/mongrel2/config/host.rb', line 75 def proxy( addr, port=80 ) return Mongrel2::Config::Proxy.create( :addr => addr, :port => port ) end |
#route(path, target, opts = {}) ⇒ Object
Add a Mongrel2::Config::Route to the Host object.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mongrel2/config/host.rb', line 50 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 |