Class: Roger::Server
- Inherits:
-
Object
- Object
- Roger::Server
- Defined in:
- lib/roger/server.rb
Overview
The Roger webserver. Initializes a rack server.
Instance Attribute Summary collapse
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#server_options ⇒ Object
readonly
Returns the value of attribute server_options.
Instance Method Summary collapse
-
#initialize(project, options = {}) ⇒ Server
constructor
A new instance of Server.
-
#map(*args, &block) ⇒ Object
Use the map handler to map endpoints to certain urls.
- #run! ⇒ Object (also: #run)
-
#set_options(options) ⇒ Object
Sets the options, this is a separate method as we want to override certain things set in the rogerfile from the commandline.
-
#use(*args, &block) ⇒ Object
Use the specified Rack middleware.
Constructor Details
#initialize(project, options = {}) ⇒ Server
Returns a new instance of Server.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/roger/server.rb', line 17 def initialize(project, = {}) @project = project @stack = initialize_rack_builder @server_options = {} # Defaults self.port = 9000 self.handler = nil self.host = "0.0.0.0" () end |
Instance Attribute Details
#handler ⇒ Object
Returns the value of attribute handler.
15 16 17 |
# File 'lib/roger/server.rb', line 15 def handler @handler end |
#host ⇒ Object
Returns the value of attribute host.
15 16 17 |
# File 'lib/roger/server.rb', line 15 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
15 16 17 |
# File 'lib/roger/server.rb', line 15 def port @port end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
13 14 15 |
# File 'lib/roger/server.rb', line 13 def project @project end |
#server_options ⇒ Object (readonly)
Returns the value of attribute server_options.
11 12 13 |
# File 'lib/roger/server.rb', line 11 def @server_options end |
Instance Method Details
#map(*args, &block) ⇒ Object
Use the map handler to map endpoints to certain urls
50 51 52 |
# File 'lib/roger/server.rb', line 50 def map(*args, &block) @stack.map(*args, &block) end |
#run! ⇒ Object Also known as: run
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/roger/server.rb', line 54 def run! project.mode = :server handler.run application, do |server| trap(:INT) do ## Use thins' hard #stop! if available, otherwise just #stop server.respond_to?(:stop!) ? server.stop! : server.stop puts "Roger, out!" end end ensure project.mode = nil end |
#set_options(options) ⇒ Object
Sets the options, this is a separate method as we want to override certain things set in the rogerfile from the commandline
34 35 36 37 38 |
# File 'lib/roger/server.rb', line 34 def () self.port = [:port] if .key?(:port) self.handler = [:handler] if .key?(:handler) self.host = [:host] if .key?(:host) end |
#use(*args, &block) ⇒ Object
Use the specified Rack middleware
43 44 45 |
# File 'lib/roger/server.rb', line 43 def use(*args, &block) @stack.use(*args, &block) end |