Class: SnowmanIO::WebServer

Inherits:
Reel::Server::HTTP
  • Object
show all
Defined in:
lib/snowman-io/web_server.rb

Defined Under Namespace

Classes: ConnectionHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ WebServer

Returns a new instance of WebServer.

Raises:

  • (ArgumentError)


89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/snowman-io/web_server.rb', line 89

def initialize(app, options)
  raise ArgumentError, "no host given" unless options[:host]
  raise ArgumentError, "no port given" unless options[:port]

  SnowmanIO.logger.info "Snowman WebServer started on http://#{options[:host]}:#{options[:port]}"

  # TODO: not sure, maybe should log without verbose option too
  app = Rack::CommonLogger.new(app, STDOUT) if options[:verbose]

  super(options[:host], options[:port], &method(:on_connection))
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/snowman-io/web_server.rb', line 6

def app
  @app
end

Instance Method Details

#on_connection(connection) ⇒ Object



102
103
104
105
# File 'lib/snowman-io/web_server.rb', line 102

def on_connection(connection)
  # connection.detach
  ConnectionHandler.new(connection, @app)
end