Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7a42de0e45
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (32 sloc) 1.348 kb
<h1>Sinatra::Extension</h1>
<p><tt>Sinatra::Extension</tt> is a mixin that provides some syntactic sugar
for your extensions. It allows you to call directly inside your extension
module almost any <tt>Sinatra::Base</tt> method. This means you can use
<tt>get</tt> to define a route, <tt>before</tt> to define a before filter,
<tt>set</tt> to define a setting, a so on.</p>
<p>Is important to be aware that this mixin remembers the methods calls you
make, and then, when your extension is registered, replays them on the
Sinatra application that has been extended. In order to do that, it
defines a <tt>registered</tt> method, so, if your extension defines one
too, remember to call <tt>super</tt>.</p>
<h2>Usage</h2>
<p>Just require the mixin and extend your extension with it:</p>
<pre>require 'sinatra/extension'
module MyExtension
extend Sinatra::Extension
# set some settings for development
configure :development do
set :reload_stuff, true
end
# define a route
get '/' do
'Hello World'
end
# The rest of your extension code goes here...
end</pre>
<p>You can also create an extension with the <tt>new</tt> method:</p>
<pre>MyExtension = Sinatra::Extension.new do
# Your extension code goes here...
end</pre>
<p>This is useful when you just want to pass a block to
<tt>Sinatra::Base.register</tt>.</p>
Jump to Line
Something went wrong with that request. Please try again.