Sha256: 55a1457ec451e3b33c55b4d3e0e7488bc7b892003f00cf04e9d493c46f31660c

Contents?: true

Size: 1.37 KB

Versions: 41

Compression:

Stored size: 1.37 KB

Contents

#!/usr/bin/env ruby

require 'mongrel2' unless defined?( Mongrel2 )
require 'mongrel2/config' unless defined?( Mongrel2::Config )

# Mongrel2 Route configuration class
class Mongrel2::Config::Route < Mongrel2::Config( :route )

	### As of Mongrel2/1.7.5:
	# CREATE TABLE route (id INTEGER PRIMARY KEY,
	#     path TEXT,
	#     reversed BOOLEAN DEFAULT 0,
	#     host_id INTEGER,
	#     target_id INTEGER,
	#     target_type TEXT);

	### Fetch the route's target, which is either a Mongrel2::Config::Directory, 
	### Mongrel2::Config::Proxy, or Mongrel2::Config::Handler object.
	def target
		case self.target_type
		when 'dir'
			return Mongrel2::Config::Directory[ self.target_id ]
		when 'proxy'
			return Mongrel2::Config::Proxy[ self.target_id ]
		when 'handler'
			return Mongrel2::Config::Handler[ self.target_id ]
		else
			raise ArgumentError, "unknown target type %p" % [ self.target_type ]
		end
	end


	### Set the target of the route to +object+, which should be one of the classes
	### returned from #target.
	def target=( object )
		case object
		when Mongrel2::Config::Directory
			self.target_type = 'dir'
		when Mongrel2::Config::Proxy
			self.target_type = 'proxy'
		when Mongrel2::Config::Handler
			self.target_type = 'handler'
		else
			raise ArgumentError, "unknown target type %p" % [ object.class ]
		end

		self.target_id = object.id
	end

end # class Mongrel2::Config::Route

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
mongrel2-0.25.0 lib/mongrel2/config/route.rb
mongrel2-0.25.0.pre.288 lib/mongrel2/config/route.rb
mongrel2-0.25.0.pre.285 lib/mongrel2/config/route.rb
mongrel2-0.24.0 lib/mongrel2/config/route.rb
mongrel2-0.23.0 lib/mongrel2/config/route.rb
mongrel2-0.22.1 lib/mongrel2/config/route.rb
mongrel2-0.21.0 lib/mongrel2/config/route.rb
mongrel2-0.20.3 lib/mongrel2/config/route.rb
mongrel2-0.20.2 lib/mongrel2/config/route.rb
mongrel2-0.20.1 lib/mongrel2/config/route.rb
mongrel2-0.19.0 lib/mongrel2/config/route.rb
mongrel2-0.18.0 lib/mongrel2/config/route.rb
mongrel2-0.17.0 lib/mongrel2/config/route.rb
mongrel2-0.16.0 lib/mongrel2/config/route.rb
mongrel2-0.15.1 lib/mongrel2/config/route.rb
mongrel2-0.15.0 lib/mongrel2/config/route.rb
mongrel2-0.14.0 lib/mongrel2/config/route.rb
mongrel2-0.13.0 lib/mongrel2/config/route.rb
mongrel2-0.12.0 lib/mongrel2/config/route.rb
mongrel2-0.11.0 lib/mongrel2/config/route.rb