Class: Hi::App
- Inherits:
-
Object
- Object
- Hi::App
- Defined in:
- lib/hi/app.rb
Overview
Main app; http server that prints requests as they come in
Constant Summary collapse
- DEFAULT_PORT =
3000
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(port = nil, logger = Hi::Logger.new) ⇒ App
constructor
A new instance of App.
- #log(message) ⇒ Object
Constructor Details
#initialize(port = nil, logger = Hi::Logger.new) ⇒ App
Returns a new instance of App.
11 12 13 14 |
# File 'lib/hi/app.rb', line 11 def initialize(port = nil, logger = Hi::Logger.new) @port = (port = port.to_i) > 0 ? port : DEFAULT_PORT @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/hi/app.rb', line 7 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/hi/app.rb', line 7 def port @port end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/hi/app.rb', line 16 def call(env) request = Hi::Request.new(env).to_h log "#{request[:request_method]} #{request[:url]} (#{Time.now})" log request [ 200, { 'Content-Type' => 'text/plain' }, ['hi'] ] end |
#log(message) ⇒ Object
25 26 27 |
# File 'lib/hi/app.rb', line 25 def log() logger.log end |