module Mojito::Controllers::Runtime

Public Class Methods

included(type) click to toggle source
# 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

Public Instance Methods

__dispatch() click to toggle source

Dispatches the current request to the matching routes.

# 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) click to toggle source

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

# 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

Private Instance Methods

__match?(matcher) click to toggle source

Evaluates a single matcher, returning whether it matched or not. Please be aware that matchers (most prominently the PATH matcher) may alter the current request, however a matcher is only allowed to do that when it matches.

# File lib/mojito/controllers/runtime.rb, line 39
def __match?(matcher)
        case matcher
        when String, Regexp
                instance_exec &PATH(matcher)
        when Proc
                instance_exec &matcher
        else
                matcher
        end
end