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
-
.map(ctrl_map = nil) ⇒ Object
(also: map=)
Helper to set the default controller map for a Server.
-
.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.
74 75 76 77 78 79 80 81 82 |
# File 'lib/nitro/server.rb', line 74 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 @options = self.class..dup @options.update() end |
Instance Attribute Details
#access_log ⇒ Object
The access_log for this server, used by Webrick.
72 73 74 |
# File 'lib/nitro/server.rb', line 72 def access_log @access_log end |
#address ⇒ Object
The server listening address.
55 56 57 |
# File 'lib/nitro/server.rb', line 55 def address @address end |
#dispatcher ⇒ Object
Return the dispatcher.
63 64 65 |
# File 'lib/nitro/server.rb', line 63 def dispatcher @dispatcher end |
#map ⇒ Object
The sitemap. Defines how controller objects are published.
47 48 49 |
# File 'lib/nitro/server.rb', line 47 def map @map end |
#name ⇒ Object
The name of the application.
43 44 45 |
# File 'lib/nitro/server.rb', line 43 def name @name end |
#options ⇒ Object
Additional server options. Useful to pass options to Webrick for example.
68 69 70 |
# File 'lib/nitro/server.rb', line 68 def @options end |
#port ⇒ Object
The server listening port.
59 60 61 |
# File 'lib/nitro/server.rb', line 59 def port @port end |
#public_root ⇒ Object
The public files root directory.
51 52 53 |
# File 'lib/nitro/server.rb', line 51 def public_root @public_root end |
Class Method Details
.map(ctrl_map = nil) ⇒ Object Also known as: map=
Helper to set the default controller map for a Server.
115 116 117 118 119 120 121 122 |
# File 'lib/nitro/server.rb', line 115 def map(ctrl_map = nil) unless ctrl_map Server.controller_map else Server.controller_map ||= {} Server.controller_map.update(ctrl_map) end end |
.run(options = {}) ⇒ Object
Helper method.
Available options:
:dispatcher, :controller
Altetnatively you can pass a single Controller class instead of the options hash.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/nitro/server.rb', line 134 def run( = {}) unless .is_a?(Hash) = { :controller => } end runner = Runner.new runner. runner.setup_mode runner.daemonize if runner.daemon Global.setup Session.setup Part.setup server = Server.new server.start() runner.invoke(server) unless $NITRO_NO_INVOKE return server end |
Instance Method Details
#root=(controller) ⇒ Object
103 104 105 |
# File 'lib/nitro/server.rb', line 103 def root=(controller) @map['/'] = controller end |
#start(options = {}) ⇒ Object
Start the server.
95 96 97 98 99 100 101 |
# File 'lib/nitro/server.rb', line 95 def start( = {}) @map['/'] = [:controller] if [:controller] @dispatcher = [:dispatcher] || Dispatcher.new(@map) @dispatcher.server = self return self end |