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
-
#adapter ⇒ Object
An instance of the configured web-server adapter.
-
#adapter_class ⇒ Object
An instance of the configured web-server adapter.
-
#configure {|config| ... } ⇒ Application
Configure the web server adapter via the passed block.
-
#initialize(configuration = Configuration.default, dispatcher = Dispatcher.new) {|app| ... } ⇒ Application
constructor
Create an Application instance.
-
#routes(&block) ⇒ Application, Array<Route>
Evaluates the passed block in the context of Dispatcher for use in adding a number of routes at once.
-
#run ⇒ Object
Starts this Application serving requests.
Constructor Details
#initialize(configuration = Configuration.default, dispatcher = Dispatcher.new) {|app| ... } ⇒ Application
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
Returns the current configuration.
27 28 29 |
# File 'lib/webmachine/application.rb', line 27 def configuration @configuration end |
#dispatcher ⇒ Dispatcher (readonly)
Returns the current dispatcher.
30 31 32 |
# File 'lib/webmachine/application.rb', line 30 def dispatcher @dispatcher end |
Instance Method Details
#adapter ⇒ Object
Returns an instance of the configured web-server adapter.
58 59 60 |
# File 'lib/webmachine/application.rb', line 58 def adapter @adapter ||= adapter_class.new(self) end |
#adapter_class ⇒ Object
Returns 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 |
#configure {|config| ... } ⇒ Application
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 |
#routes(&block) ⇒ Application, Array<Route>
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 |
#run ⇒ Object
Starts this Application serving requests
52 53 54 |
# File 'lib/webmachine/application.rb', line 52 def run adapter.run end |