Class: IrcMachine::HttpController

Inherits:
Object
  • Object
show all
Defined in:
lib/irc_machine/http_controller.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, request, match) ⇒ HttpController

Returns a new instance of HttpController.



10
11
12
13
14
15
# File 'lib/irc_machine/http_controller.rb', line 10

def initialize(session, request, match)
  @session = session
  @request = request
  @match = match
  @response = Rack::Response.new
end

Instance Attribute Details

#matchObject (readonly)

Returns the value of attribute match.



19
20
21
# File 'lib/irc_machine/http_controller.rb', line 19

def match
  @match
end

#requestObject (readonly)

Returns the value of attribute request.



18
19
20
# File 'lib/irc_machine/http_controller.rb', line 18

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



18
19
20
# File 'lib/irc_machine/http_controller.rb', line 18

def response
  @response
end

#sessionObject (readonly)

Returns the value of attribute session.



17
18
19
# File 'lib/irc_machine/http_controller.rb', line 17

def session
  @session
end

Class Method Details

.dispatch(session, request, method, match) ⇒ Object



4
5
6
7
8
# File 'lib/irc_machine/http_controller.rb', line 4

def self.dispatch(session, request, method, match)
  new(session, request, match).tap do |c|
    c.send method
  end.response
end

Instance Method Details

#content_type(type) ⇒ Object



30
31
32
# File 'lib/irc_machine/http_controller.rb', line 30

def content_type(type)
  @response["Content-Type"] = type
end

#not_foundObject



26
27
28
# File 'lib/irc_machine/http_controller.rb', line 26

def not_found
  @response.status = 404
end

#ok(content) ⇒ Object



21
22
23
24
# File 'lib/irc_machine/http_controller.rb', line 21

def ok(content)
  @response.status = 200
  @response.write content
end