Module: Sinatra::Settings
- Defined in:
- lib/sinatra/settings.rb
Overview
Sinatra::Settings
A Sinatra Extension that shows your app’s settings and other debug information.
Ever wanted an overview of all Sinatra settings (formerly options) in your app?
Well, now you can through this Sinatra Extension which makes that task dead simple, while also adding in some other useful debug information in the output.
With a heavy dose of inspiration taken from Sinatra’s Show Exception output page.
Installation
# Add Gemcutter to your RubyGems sources
$ gem sources -a http://gemcutter.com
$ (sudo)? gem install sinatra-settings
Dependencies
This Gem depends upon the following:
Runtime:
-
sinatra ( >= 1.0 )
Development & Tests:
-
rspec (>= 1.3.0 )
-
rack-test (>= 0.5.3)
-
rspec_hpricot_matchers (>= 0.1.0)
-
sinatra-tests (>= 0.1.6)
Getting Started
To view the settings in your app, just require and register the extension in your sub-classed Sinatra app:
require 'sinatra/settings'
class YourApp < Sinatra::Base
register(Sinatra::Settings)
enable :show_settings # turn it on
<snip...>
end
In your “classic” Sinatra app, you just require the extension like this:
require 'rubygems'
require 'sinatra'
require 'sinatra/settings'
<snip...>
Then at the bottom of your App’s layout - layout.(erb|haml)
add the following:
<snip...>
<%= show_settings_output? %>
</body>
</html>
Reload your app and view the added content at the bottom of your page.
You can see an example of the output here:
That’s really all there is.
Configuration Options
By default, these are the settings:
# don't show settings by default
set :show_settings, false
# only show the settings in development mode.
set :show_settings_environment, :development
Apart from turning it On / Off, you can also set the output to show up in :production
or :test
enviroments.
The advantage of having two configuration ‘switches’ is that you can leave all the code as is, and in :development
it will show the output, but in :production
no output will be shown (other than a tiny HTML comment telling you it’s Off)
That’s it. I hope that’s easy enough.
TODOs
-
Decide whether this functionality should really be incorporated into a Sinatra::Debug extension instead.
-
Any other improvements you or I can think of.
Copyright
Copyright © 2010 kematzy. Released under the MIT License.
See LICENSE for details.
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- VERSION =
'0.1.2'
Class Method Summary collapse
Class Method Details
.registered(app) ⇒ Object
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/sinatra/settings.rb', line 448 def self.registered(app) app.helpers Sinatra::Settings::Helpers # don't show settings by default app.set :show_settings, false # only show the settings in development mode. app.set :show_settings_environment, :development ## add the extension specific settings to those inspectable by the :settings_inspect method if app.respond_to?(:sinatra_settings_for_inspection) %w(show_settings show_settings_environment).each do |s| app.sinatra_settings_for_inspection << s end end end |
.version ⇒ Object
145 |
# File 'lib/sinatra/settings.rb', line 145 def self.version; "Sinatra::Settings v#{VERSION}"; end |