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
- #application_options ⇒ Object
-
#auto_port ⇒ Object
Returns the value of attribute auto_port.
-
#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
-
#server_options ⇒ Object
readonly
Returns the value of attribute server_options.
- #used_handler ⇒ Object readonly
- #used_port ⇒ Object readonly
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)
- #server_options_for_handler ⇒ Object
-
#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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/roger/server.rb', line 36 def initialize(project, = {}) @project = project @stack = initialize_rack_builder @server_options = {} # Defaults self.port = 9000 self.handler = nil self.host = "0.0.0.0" self.auto_port = true @used_port = nil @used_handler = nil () end |
Instance Attribute Details
#application_options ⇒ Object
34 35 36 |
# File 'lib/roger/server.rb', line 34 def @application_options end |
#auto_port ⇒ Object
Returns the value of attribute auto_port.
29 30 31 |
# File 'lib/roger/server.rb', line 29 def auto_port @auto_port end |
#handler ⇒ Object
Returns the value of attribute handler.
29 30 31 |
# File 'lib/roger/server.rb', line 29 def handler @handler end |
#host ⇒ Object
Returns the value of attribute host.
29 30 31 |
# File 'lib/roger/server.rb', line 29 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
29 30 31 |
# File 'lib/roger/server.rb', line 29 def port @port end |
#project ⇒ Object (readonly)
19 20 21 |
# File 'lib/roger/server.rb', line 19 def project @project end |
#server_options ⇒ Object (readonly)
Returns the value of attribute server_options.
16 17 18 |
# File 'lib/roger/server.rb', line 16 def @server_options end |
#used_handler ⇒ Object (readonly)
27 28 29 |
# File 'lib/roger/server.rb', line 27 def used_handler @used_handler end |
#used_port ⇒ Object (readonly)
23 24 25 |
# File 'lib/roger/server.rb', line 23 def used_port @used_port end |
Instance Method Details
#map(*args, &block) ⇒ Object
Use the map handler to map endpoints to certain urls
74 75 76 |
# File 'lib/roger/server.rb', line 74 def map(*args, &block) @stack.map(*args, &block) end |
#run! ⇒ Object Also known as: run
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/roger/server.rb', line 78 def run! project.mode = :server = @used_port = [:Port] @used_handler = handler 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 yield server if block_given? end ensure project.mode = nil @used_port = nil @used_handler = nil end |
#server_options_for_handler ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/roger/server.rb', line 101 def # Search for available port = .dup if auto_port && !port_free?([:Host], [:Port]) [:Port] = free_port_for_host_above([:Host], [:Port]) end # Return the options 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
57 58 59 60 61 62 |
# File 'lib/roger/server.rb', line 57 def () self.port = [:port].to_i if .key?(:port) self.handler = [:handler] if .key?(:handler) self.host = [:host] if .key?(:host) self.auto_port = [:auto_port] if .key?(:auto_port) end |
#use(*args, &block) ⇒ Object
Use the specified Rack middleware
67 68 69 |
# File 'lib/roger/server.rb', line 67 def use(*args, &block) @stack.use(*args, &block) end |