Module: Mojito::ClassMethods

Defined in:
lib/mojito.rb,
lib/mojito/base.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



64
65
66
67
68
69
# File 'lib/mojito/base.rb', line 64

def call(env)
	catch :halt do
		request = Rack::Request.new env
		dispatch request
	end
end

#controller(name, options = {}) ⇒ Object



43
44
45
46
47
48
# File 'lib/mojito.rb', line 43

def controller(name, options = {})
	mod = Mojito::Controllers.const_get name.to_s.camel_case.to_sym
	[*options[:rendering]].each {|r| rendering r }
	[*options[:helpers]].each {|h| helper h }
	include mod
end

#dispatch(request) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mojito/base.rb', line 71

def dispatch(request)
	controller = self.new request
	begin
		controller.__dispatch
	rescue Exception => e
		if controller.respond_to? :__handle_error
			controller.__handle_error(e)
		else
			raise e
		end
	end
end

#helper(name, options = {}) ⇒ Object



50
51
52
53
# File 'lib/mojito.rb', line 50

def helper(name, options = {})
	mod = Mojito::Helpers.const_get name.to_s.camel_case.to_sym
	include mod
end

#mock_requestObject



39
40
41
# File 'lib/mojito.rb', line 39

def mock_request
	Rack::MockRequest.new self
end

#rendering(name, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/mojito.rb', line 55

def rendering(name, options = {})
	mod = case name
	when :all
		Mojito::Rendering
	else
		Mojito::Rendering.const_get name.to_s.camel_case.to_sym
	end
	include mod
end