Class: Nitro::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/nitro/server.rb

Defined Under Namespace

Classes: Mounter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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', options = {})
  @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.options.dup
  @options.update(options)
end

Instance Attribute Details

#access_logObject

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

#addressObject

The server listening address.



47
48
49
# File 'lib/nitro/server.rb', line 47

def address
  @address
end

#dispatcherObject

Return the dispatcher.



55
56
57
# File 'lib/nitro/server.rb', line 55

def dispatcher
  @dispatcher
end

#mapObject

The sitemap. Defines how controller objects are published.



39
40
41
# File 'lib/nitro/server.rb', line 39

def map
  @map
end

#nameObject

The name of the application.



35
36
37
# File 'lib/nitro/server.rb', line 35

def name
  @name
end

#optionsObject

Additional server options. Useful to pass options to Webrick for example.



60
61
62
# File 'lib/nitro/server.rb', line 60

def options
  @options
end

#portObject

The server listening port.



51
52
53
# File 'lib/nitro/server.rb', line 51

def port
  @port
end

#public_rootObject

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(options = {})
  unless options.is_a?(Hash)
    options = { :controller => options }
  end

  runner = Runner.new
  runner.setup_options
  runner.setup_mode
  runner.daemonize if runner.daemon  

  unless Session.cache
    require 'nitro/session/memory'
  end
  
  server = Server.new
  server.start(options)
   
  runner.invoke(server) unless $NITRO_NO_INVOKE
  
  return server
end

Instance Method Details

#rootObject



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(options = {})    
  @map['/'] = options[:controller] if options[:controller]
  @dispatcher = options[:dispatcher] || Dispatcher.new(@map)

  return self
end