Module: Mojito::Controllers::Runtime

Defined in:
lib/mojito/controllers/runtime.rb,
lib/mojito/controllers/runtime/path.rb,
lib/mojito/controllers/runtime/methods.rb,
lib/mojito/controllers/runtime/session.rb,
lib/mojito/controllers/runtime/url_scheme.rb,
lib/mojito/controllers/runtime/environment.rb,
lib/mojito/controllers/runtime/virtual_host.rb

Defined Under Namespace

Modules: ClassMethods, Environment, Methods, Path, Session, UrlScheme, VirtualHost

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(type) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/mojito/controllers/runtime.rb', line 12

def self.included(type)
	type.extend ClassMethods
	type.instance_exec do
		include Environment
		include Methods
		include Path
		include UrlScheme
		include VirtualHost
	end
end

Instance Method Details

#__dispatchObject

Dispatches the current request to the matching routes.



53
54
55
56
# File 'lib/mojito/controllers/runtime.rb', line 53

def __dispatch
	instance_exec &self.class.routes if self.class.routes
	[404, { 'Content-Type' => 'application/octet-stream' }, []]
end

#on(*matchers, &block) ⇒ Object

Defines a route which is matched when all given matchers evaluate to true.



25
26
27
28
29
30
31
32
33
34
# File 'lib/mojito/controllers/runtime.rb', line 25

def on(*matchers, &block)
	env_backup = env.dup
	param_size = request.captures.length
	return unless matchers.all? {|m| __match?(m) }
	params = request.captures[param_size..-1][0..block.arity].collect {|p| Rack::Utils.unescape(p) }
	instance_exec *params, &block
ensure
	@__env = env_backup
	request.instance_exec { @env = env_backup }
end