Class: ASeriesOfTubes::TubeController

Inherits:
Object
  • Object
show all
Defined in:
lib/a_series_of_tubes/tube_controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(request, response, params = {}) ⇒ TubeController

Returns a new instance of TubeController.



7
8
9
10
11
# File 'lib/a_series_of_tubes/tube_controller.rb', line 7

def initialize request, response, params = {}
  @request = request
  @response = response
  @params = params.merge request.params
end

Instance Method Details

#flashObject



47
48
49
# File 'lib/a_series_of_tubes/tube_controller.rb', line 47

def flash
  @flash ||= self.session.flash
end

#invoke_action(action) ⇒ Object



13
14
15
16
# File 'lib/a_series_of_tubes/tube_controller.rb', line 13

def invoke_action action
  self.send action
  render action unless @rendered
end

#redirect_to(url) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/a_series_of_tubes/tube_controller.rb', line 18

def redirect_to url
  prevent_double_render
  set_rendered

  self.response.header['location'] = url
  self.response.status = 302
  self.session.store_session self.response
end

#render(template_name) ⇒ Object



27
28
29
30
31
32
# File 'lib/a_series_of_tubes/tube_controller.rb', line 27

def render template_name
  controller_name = self.class.to_s.underscore
  filename = "#{APP_DIRECTORY}/views/#{controller_name}/#{template_name}.html.erb"
  render_content ERB.new(File.read(filename)).result(binding), 'text/html'
  self.session.store_session self.response
end

#render_content(content, content_type) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/a_series_of_tubes/tube_controller.rb', line 34

def render_content content, content_type
  prevent_double_render
  set_rendered

  self.response['Content-Type'] = content_type
  self.response.write content
  self.session.store_session self.response
end

#sessionObject



43
44
45
# File 'lib/a_series_of_tubes/tube_controller.rb', line 43

def session
  @session ||= TubeState::Session.new self.request
end