Class: Nitro::Server
- Inherits:
-
Object
- Object
- Nitro::Server
- Defined in:
- lib/nitro/server.rb
Defined Under Namespace
Classes: Mounter
Instance Attribute Summary collapse
-
#access_log ⇒ Object
The access_log for this server, used by Webrick.
-
#address ⇒ Object
The server listening address.
-
#dispatcher ⇒ Object
Return the dispatcher.
-
#map ⇒ Object
The sitemap.
-
#name ⇒ Object
The name of the application.
-
#options ⇒ Object
Additional server options.
-
#port ⇒ Object
The server listening port.
-
#public_root ⇒ Object
The public files root directory.
Class Method Summary collapse
-
.run(options = {}) ⇒ Object
Helper method.
Instance Method Summary collapse
-
#initialize(name = 'Nitro', options = {}) ⇒ Server
constructor
A new instance of Server.
- #root ⇒ Object
- #root=(controller) ⇒ Object
-
#start(options = {}) ⇒ Object
Start the server.
Constructor Details
#initialize(name = 'Nitro', options = {}) ⇒ Server
Returns a new instance of Server.
66 67 68 69 70 71 72 73 74 |
# File 'lib/nitro/server.rb', line 66 def initialize(name = 'Nitro', = {}) @name = name @map = self.class.map.dup @address, @port = self.class.address, self.class.port @public_root = self.class.public_root @access_log = self.class.access_log = self.class..dup .update() end |
Instance Attribute Details
#access_log ⇒ Object
The access_log for this server, used by Webrick.
64 65 66 |
# File 'lib/nitro/server.rb', line 64 def access_log @access_log end |
#address ⇒ Object
The server listening address.
47 48 49 |
# File 'lib/nitro/server.rb', line 47 def address @address end |
#dispatcher ⇒ Object
Return the dispatcher.
55 56 57 |
# File 'lib/nitro/server.rb', line 55 def dispatcher @dispatcher end |
#map ⇒ Object
The sitemap. Defines how controller objects are published.
39 40 41 |
# File 'lib/nitro/server.rb', line 39 def map @map end |
#name ⇒ Object
The name of the application.
35 36 37 |
# File 'lib/nitro/server.rb', line 35 def name @name end |
#options ⇒ Object
Additional server options. Useful to pass options to Webrick for example.
60 61 62 |
# File 'lib/nitro/server.rb', line 60 def end |
#port ⇒ Object
The server listening port.
51 52 53 |
# File 'lib/nitro/server.rb', line 51 def port @port end |
#public_root ⇒ Object
The public files root directory.
43 44 45 |
# File 'lib/nitro/server.rb', line 43 def public_root @public_root end |
Class Method Details
.run(options = {}) ⇒ Object
Helper method.
Available options:
:dispatcher, :controller
Altetnatively you can pass a single Controller class instead of the options hash.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/nitro/server.rb', line 111 def self.run( = {}) unless .is_a?(Hash) = { :controller => } end runner = Runner.new runner. runner.setup_mode runner.daemonize if runner.daemon unless Session.cache require 'nitro/session/memory' end server = Server.new server.start() runner.invoke(server) unless $NITRO_NO_INVOKE return server end |
Instance Method Details
#root ⇒ Object
98 99 100 |
# File 'lib/nitro/server.rb', line 98 def root Mounter.new(self) end |
#root=(controller) ⇒ Object
94 95 96 |
# File 'lib/nitro/server.rb', line 94 def root=(controller) @map['/'] = controller end |
#start(options = {}) ⇒ Object
Start the server.
87 88 89 90 91 92 |
# File 'lib/nitro/server.rb', line 87 def start( = {}) @map['/'] = [:controller] if [:controller] @dispatcher = [:dispatcher] || Dispatcher.new(@map) return self end |