Class: Flame::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/flame/controller.rb

Overview

Class initialize when Dispatcher found route with it For new request and response

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher) ⇒ Controller

Returns a new instance of Controller.



8
9
10
# File 'lib/flame/controller.rb', line 8

def initialize(dispatcher)
	@dispatcher = dispatcher
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Helpers from Flame::Dispatcher



35
36
37
38
# File 'lib/flame/controller.rb', line 35

def method_missing(m, *args, &block)
	return super unless @dispatcher.respond_to?(m)
	@dispatcher.send(m, *args, &block)
end

Instance Method Details

#path_to(*args) ⇒ Object

Helpers



13
14
15
16
# File 'lib/flame/controller.rb', line 13

def path_to(*args)
	args.unshift self.class if args[0].is_a? Symbol
	@dispatcher.path_to(*args)
end

#redirect(*params) ⇒ Object



18
19
20
21
22
# File 'lib/flame/controller.rb', line 18

def redirect(*params)
	response.redirect(
		params[0].is_a?(String) ? params[0] : path_to(*params)
	)
end

#view(path = nil, options = {}) ⇒ Object Also known as: render



24
25
26
27
28
29
30
31
# File 'lib/flame/controller.rb', line 24

def view(path = nil, options = {})
	template = Flame::Render.new(
		self,
		(path || caller_locations(1, 1)[0].label.to_sym),
		options
	)
	template.render(cache: config[:environment] == 'production')
end