Module: Mojito::Controllers::Method

Defined in:
lib/mojito/controllers/method.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.args_for(arity, path_info) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mojito/controllers/method.rb', line 30

def self.args_for(arity, path_info)
	if arity >= 0
		args = path_info.split('/', arity + 1)
		if args.length == arity
			[args, '']
		elsif args.length == arity + 1
			[args, args.pop]
		else
			[nil, path_info]
		end
	else
		args = path_info.split('/')
		if args.length >= arity.abs - 1
			[args, '']
		else
			[nil, path_info]
		end
	end
end

Instance Method Details

#__dispatchObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mojito/controllers/method.rb', line 8

def __dispatch
	if m = %r{^/?(?<meth>\w+)(?:/|$)}.match(request.path_info)
		meth = m['meth'].to_sym
		if respond_to?(meth.to_sym)
			env['SCRIPT_NAME'] += m.to_s
			arity = method(meth).arity
			args, env['PATH_INFO'] = Method.args_for(arity, m.post_match)
			args.collect! {|a| CGI.unescape a } if args
			if args
				send meth, *args
				ok!
			else
				Mojito::R::StatusCodes.instance_method(:not_found!).bind(self).call
			end
		else
			Mojito::R::StatusCodes.instance_method(:not_found!).bind(self).call
		end
	else
		Mojito::R::StatusCodes.instance_method(:not_found!).bind(self).call
	end
end