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.10.0 lib/mongrel2/config/route.rb
mongrel2-0.9.2 lib/mongrel2/config/route.rb
mongrel2-0.9.1 lib/mongrel2/config/route.rb
mongrel2-0.9.0 lib/mongrel2/config/route.rb
mongrel2-0.8.0 lib/mongrel2/config/route.rb
mongrel2-0.7.0 lib/mongrel2/config/route.rb
mongrel2-0.6.0 lib/mongrel2/config/route.rb
mongrel2-0.5.0 lib/mongrel2/config/route.rb
mongrel2-0.4.0 lib/mongrel2/config/route.rb
mongrel2-0.3.1 lib/mongrel2/config/route.rb
mongrel2-0.3.0 lib/mongrel2/config/route.rb
mongrel2-0.2.4 lib/mongrel2/config/route.rb
mongrel2-0.2.3 lib/mongrel2/config/route.rb
mongrel2-0.2.2 lib/mongrel2/config/route.rb
mongrel2-0.2.1 lib/mongrel2/config/route.rb
mongrel2-0.2.0 lib/mongrel2/config/route.rb
mongrel2-0.1.2 lib/mongrel2/config/route.rb
mongrel2-0.1.1 lib/mongrel2/config/route.rb
mongrel2-0.1.0 lib/mongrel2/config/route.rb
mongrel2-0.0.2 lib/mongrel2/config/route.rb