Methods
Attributes
| [RW] | adapter | The adapter used to interface with the front web servers. |
| [RW] | address | The listening address. |
| [RW] | compiler | The compiler generates action methods for the controllers. |
| [RW] | dispatcher | The dispatcher. |
| [RW] | handle_static_files | Handle static files? Set to true in live mode to avoid a nasty bug: when caching is enabled and the index method accepts parameters, static files may get corrupted. Think something better. |
| [RW] | name | The name of the Server. |
| [RW] | options | General options. |
| [RW] | port | The listening port |
| [RW] | public_dir | The public directory. All files that are placed here a publicly accessible through the webserver. |
| [RW] | session_store | The session store. |
| [RW] | temp_dir | The temporary files dir. Put all your temporal files here to keep the directory structure clean. |
Public Class methods
[ show source ]
# File lib/nitro/application.rb, line 63
63: def initialize(name = "Nitro Application", options = {})
64: @name = name
65: @options = options
66: @address = "0.0.0.0"
67: @port = 9000
68: @compiler = Raw::Compiler.new(self)
69: @adapter = :webrick
70: @dispatcher = Raw::Dispatcher.new
71: @public_dir = File.expand_path("public")
72: @temp_dir = File.expand_path(".temp")
73: @handle_static_files = true
74: end
Public Instance methods
Return the adapter of this server. If necessary resolves the adapter.
[ show source ]
# File lib/nitro/application.rb, line 79
79: def adapter
80: if @adapter.is_a? Symbol
81: require "raw/adapter/" + @adapter.to_s
82: @adapter = constant("Raw::#{@adapter.to_s.camelize}Adapter").new
83: end
84:
85: return @adapter
86: end
Apply some default settings for the selected execution mode and then apply the application specific confuguration settings.
[ show source ]
# File lib/nitro/application.rb, line 154
154: def configure
155: read_arguments()
156: read_environment()
157:
158: # Some reasonable defaults.
159:
160: case Nitro.mode
161: when :debug
162: $DBG = true
163: @compiler.reloader.start(3)
164: Raw::Caching.enabled = false
165: else
166: # Enable the reloading even on live apps by default.
167: # But have a longer thread sleep time. If you really
168: # need sligthly faster dispatching disable reloading
169: # (don't start the reloader).
170: @compiler.reloader.start(2 * 60)
171: end
172:
173: read_configuration_file()
174:
175: # Force the adapter defined in the environment.
176:
177: @adapter = @force_adapter if @force_adapter
178: end
Read configuration options from the command line arguments (ARGV).
[ show source ]
# File lib/nitro/application.rb, line 128
128: def read_arguments
129: ap = Args.new([])
130: ap.application = self
131: ap.execute
132: end
Read configuration options from the configuration file
[ show source ]
# File lib/nitro/application.rb, line 143
143: def read_configuration_file
144: require "conf/" + Nitro.mode.to_s
145: setup(self)
146: rescue LoadError => ex
147: pp_exception(ex)
148: end
Read configuration options from the environment (ENV).
[ show source ]
# File lib/nitro/application.rb, line 136
136: def read_environment
137: Nitro.mode ||= ENV.fetch("NITRO_MODE", :debug).to_sym
138: @force_adapter = ENV.fetch("NITRO_ADAPTER", :webrick).to_sym
139: end
Start the application.
[ show source ]
# File lib/nitro/application.rb, line 90
90: def start
91: ensure_support_directories()
92: configure()
93:
94: Global.setup
95: Part.setup(self)
96:
97: require "raw/context/session/cookie"
98: @session_store = Raw::CookieSessionStore.new
99:
100: if dispatcher.router
101: for path, c in dispatcher.controllers
102: dispatcher.router.add_rules_from_annotations(c)
103: end
104: end
105:
106: if defined? :Og
107: require "raw/model/enchant"
108: for m in Og.manager.models
109: m.send(:include, Enchant)
110: end
111: end
112:
113: Aspects.setup
114:
115: adapter.start(self)
116: end
Stop the application.
[ show source ]
# File lib/nitro/application.rb, line 120
120: def stop
121: Part.finalize(self)
122: adapter.stop()
123: end