Hoboken

Basic Features

All projects generated with Hoboken have the following common features:

  • includes a Rakefile with tasks for starting the development server and running tests
  • uses Thin as the default web server
  • the contest gem for testing support
  • Rack::Csrf is turned on by default
  • environment variable support via the dotenv gem
  • Sinatra reloader is enabled for the development environment
  • custom Rack::Test assertions
  • a base class helper for Rack based tests

Project Structure

Projects are generated with the following structure:

Gemfile Your app's dependencies
README.md A sample README
Rakefile Basic app tasks
app.rb The main application file
config.ru Rackup file
/helpers Any helper files
/public Static assets (i.e. css, js, images)
/test Basic unit test and test helper support
/views Your app's views (not present if --tiny option was used)

The app.rb file contains the main Sinatra application. If the --modular option is used, the application will inherit from Sinatra::Base. Refer to the Sinatra documentation on classic vs. modular applications for more information.

General Command Reference

generate

Generate a new Sinatra app

$ hoboken generate [APP_NAME]

Options

[--ruby-version=RUBY_VERSION]
Specify a Ruby version for the Gemfile. By default it will use the currently installed version.
[--tiny], [--no-tiny]
Generate views inline; do not create /public folder
[--type=TYPE]
Architecture type (classic or modular). Default is classic.
[--git], [--no-git]
Create a Git repository and make initial commit

Rake Tasks

By default all newly generated projects will have the following Rake tasks available.

$ rake server
Start the development server
$ rake test:all
Run all tests
$ rake test:integration
Run tests for integration
$ rake test:unit
Run tests for unit

help

Describe available commands. If COMMAND is given, describe the specific COMMAND.

$ hoboken help [COMMAND]


version

Print version and quit.

$ hoboken version


Add On Command Reference

Heroku

Heroku deployment support.

$ hoboken add:heroku

Adds foreman to the project's dependencies and updates the rake server task to use it. It also creates a Procfile so that Heroku can start your application. A .slugignore file is also created.


Internationalization

Internationalization support using sinatra-r18n.

$ hoboken add:i18n

Adds the sinatra-r18n gem to the project's dependencies and creates an i18n folder with a sample translation file.


Metrics

Adds metrics utilities to project (flog, flay, simplecov).

$ hoboken add:metrics

Adds flog, flay, and simplecov to the project dependencies. Adds two rake tasks for running flog and flay. Modifies the test rake tasks to run with simplecov. The coverage report is generated in the tmp/coverage folder.


Omniauth

Authentication capability via the Omniauth gem.

$ hoboken add:omniauth

Running this command will prompt you to select an Omniauth provider and version. It will stub out 3 new handlers for Omniauth in app.rb. In addition, it will create unit tests for the stubbed out handlers.


Sequel

Provides database support via the Sequel gem.

$ hoboken add:sequel

Adds the Sequel gem as a dependency. Also adds the sqlite3 gem for dev and test environments. You will need to specify your own database provider for production. Access to the database is handled via DATABASE_URL which either needs to be exported as an environment variable or added to the project's .env file. The config.ru is adjusted to set up the database. The settings feature of Sinatra is used to create a database setting that can be used within the application.

A db/migrate folder is created for migrations. Two rake tasks for migrations are also created:

$ rake db:migrate
Migrate the database to the latest version.
$ rake db:reset
Perform migration reset (full erase and migration up).

The project's test_helper.rb is adjusted to include a helper class for unit tests that touch the database. When a unit test class inherits from this, it will set up an in memory database and apply any migrations. Each test is run in the context of a transaction that will be rolled back after each test is run.


Sprockets

Add Sprockets support to the project.

$ hoboken add:sprockets

Sets up an /assets folder and a assets:precompile Rake task. Adjusts app.rb to include the Sprockets middleware extension for serving assets in development. For production, assets should be precompiled using the Rake task.

Important Note: Any css or js files from the /public folder have been copied to /assets, the original files remain intact in /public, but will be replaced the first time you run rake assets:precompile. You may want to backup those files if they are not under source control before running the Rake command.


Travis CI

Basic Travis-CI YAML config.

$ hoboken add:travis

Sets up a minimal .travis.yml file.