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
$ (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.
RTFM
If the above is not clear enough, please check the Specs for a better understanding.
Errors / Bugs
If something is not behaving intuitively, it is a bug, and should be reported. Report it here: github.com/kematzy/sinatra-settings/issues
TODOs
-
Decide whether this functionality should really be incorporated into a Sinatra::Debug extension instead.
-
Any other improvements you or I can think of.
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history.
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010 kematzy. Released under the MIT License.
See LICENSE for details.