class Webmachine::Application
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
Attributes
@return [Configuration] the current configuration
@return [Dispatcher] the current dispatcher
Public Class Methods
Create an Application
instance
An instance of application contains Adapter
configuration and a Dispatcher
instance which can be configured with Routes.
@param [Webmachine::Configuration] configuration
a Webmachine::Configuration
@yield [app]
a block in which to configure this Application
@yieldparam [Application]
the Application instance being initialized
# 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
Public Instance Methods
@return an instance of the configured web-server adapter @see Adapters
# File lib/webmachine/application.rb, line 58 def adapter @adapter ||= adapter_class.new(self) end
@return an instance of the configured web-server adapter @see Adapters
# File lib/webmachine/application.rb, line 64 def adapter_class Adapters.const_get(configuration.adapter) end
Configure the web server adapter via the passed block
Returns the receiver so you can chain it with Application#run
@yield [config]
a block in which to set configuration values
@yieldparam [Configuration]
config the Configuration instance
@return [Application] self
# File lib/webmachine/application.rb, line 94 def configure yield configuration if block_given? self end
Evaluates the passed block in the context of {Webmachine::Dispatcher} for use in adding a number of routes at once.
@return [Application, Array<Route>]
self if configuring, or an Array of Routes otherwise
@see Webmachine::Dispatcher#add_route
# File lib/webmachine/application.rb, line 75 def routes(&block) if block dispatcher.instance_eval(&block) self else dispatcher.routes end end
Starts this Application
serving requests
# File lib/webmachine/application.rb, line 52 def run adapter.run end