Knowledge Base: Project Hooks

Introducing Hooks

By default, when preparing your project to run tests Devver will use commands which work for a typical Ruby on Rails project. Everyone's project is different, however, and your project may require special steps to be performed when it is first set up, or when project files are changed. In order to accommodate varying project configurations, Devver supports a system of "hooks" - user-customizable actions which are executed at certain points in the Devver project life cycle.

Hook Basics

Hooks in a Devver project take the form of executable scripts located in the .devver/hooks directory inside your project's root directory. Each script is named for a specific stage of the Devver project sync/distribute/run life cycle. For instance, the prepare_database hook is responsible for preparing a project's database (created in an earlier stage) for tests to be run against it.

Devver hooks can be UNIX Bourne shell scripts or Ruby scripts. Their type is determined by the "shebang line" at the top of the file. For instance, a Bourne shell script would begin with the line:

#!/bin/sh

while a Ruby script would begin with:

#!/usr/bin/env ruby

All hooks are executed in the project root directory. Some scripts may receive input from Devver in the form of command-line arguments, text on STDIN, or special environment variables. See documentation for individual hooks for what inputs will be provided to the hook at runtime.

When your project is first initialized, a default set of hooks is copied into the project's hooks directory. These default hook templates contain further documentation for individual hooks.

List of Hooks

install_dependencies

This hook is run after your project is synced to the Devver servers and before the database is prepared. It is responsible for installing any software, such as RubyGems, that the project depends on in order to run.

prepare_database

This hook is run after a project's database is created and before any tests are run. It should create the application tables and load any data which is needed for the tests to run. For instance, a typical prepare_database hook for a Rails project would run the db:migrate or db:schema:load Rake tasks.

API-only Hooks

The following hooks are applicable only to users of the Devver API:

build

This hook defines how to run a full "build" of your project. By default it simply runs the rake command in the project root directory.

The build hook is intended to be used in conjunction with the Devver API.

notify

This hook enables you to customise how Devver notifies you of the results of actions triggered through the Devver API. By default it attempts to send results via email. You must edit this hook and add your email address in order to receive email notifications from the Devver API.