Class: Webmachine::Application
- Inherits:
-
Object
- Object
- Webmachine::Application
- Extended by:
- Forwardable
- Defined in:
- lib/webmachine/application.rb
Overview
How to get your Webmachine app running:
MyApp = Webmachine::Application.new do |app|
app.routes do
add ['*'], AssetResource
end
app.configure do |config|
config.port = 8888
end
end
MyApp.run
Instance Attribute Summary (collapse)
-
- (Configuration) configuration
The current configuration.
-
- (Dispatcher) dispatcher
readonly
The current dispatcher.
Instance Method Summary (collapse)
-
- (Object) adapter
An instance of the configured web-server adapter.
-
- (Object) adapter_class
An instance of the configured web-server adapter.
-
- (Application) configure {|config| ... }
Configure the web server adapter via the passed block.
-
- (Application) initialize(configuration = Configuration.default, dispatcher = Dispatcher.new) {|app| ... }
constructor
Create an Application instance.
-
- (Application, Array<Route>) routes(&block)
Evaluates the passed block in the context of Dispatcher for use in adding a number of routes at once.
-
- (Object) run
Starts this Application serving requests.
Constructor Details
- (Application) initialize(configuration = Configuration.default, dispatcher = Dispatcher.new) {|app| ... }
Create an Application instance
An instance of application contains Adapter configuration and a Dispatcher instance which can be configured with Routes.
44 45 46 47 48 49 |
# File 'lib/webmachine/application.rb', line 44 def initialize(configuration = Configuration.default, dispatcher = Dispatcher.new) @configuration = configuration @dispatcher = dispatcher yield self if block_given? end |
Instance Attribute Details
- (Configuration) configuration
The current configuration
27 28 29 |
# File 'lib/webmachine/application.rb', line 27 def configuration @configuration end |
- (Dispatcher) dispatcher (readonly)
The current dispatcher
30 31 32 |
# File 'lib/webmachine/application.rb', line 30 def dispatcher @dispatcher end |
Instance Method Details
- (Object) adapter
An instance of the configured web-server adapter
58 59 60 |
# File 'lib/webmachine/application.rb', line 58 def adapter @adapter ||= adapter_class.new(configuration, dispatcher) end |
- (Object) adapter_class
An instance of the configured web-server adapter
64 65 66 |
# File 'lib/webmachine/application.rb', line 64 def adapter_class Adapters.const_get(configuration.adapter) end |
- (Application) configure {|config| ... }
Configure the web server adapter via the passed block
Returns the receiver so you can chain it with Application#run
94 95 96 97 |
# File 'lib/webmachine/application.rb', line 94 def configure yield configuration if block_given? self end |
- (Application, Array<Route>) routes(&block)
Evaluates the passed block in the context of Dispatcher for use in adding a number of routes at once.
75 76 77 78 79 80 81 82 |
# File 'lib/webmachine/application.rb', line 75 def routes(&block) if block_given? dispatcher.instance_eval(&block) self else dispatcher.routes end end |
- (Object) run
Starts this Application serving requests
52 53 54 |
# File 'lib/webmachine/application.rb', line 52 def run adapter.run end |