Graffable

Sinatra-based data charting application

Installation

Add this line to your application's Gemfile:

gem 'graffable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install graffable

Usage

Set environment variables:

% export GRAFFABLE_DATABASE_URL=sqlite://path/to/db.sqlite3
% export GRAFFABLE_SEED_FILE=/path/to/seed.rb

Create seed file:

require 'graffable'

DB = Graffable::Database.connect

# Report Groups
[
  [ 'a', 'Service A' ],
  [ 'b', 'Host B',   ]
].each do |tuple|
  DB[:groups].insert name: tuple.first, description: tuple.last
end

# Reports
{
  'a' => {
    'report-a1' => [ 'Name of report', :sum ],
    'report-a2' => [ 'Name of report', :avg ],
  },
  'b' => {
    'report-b1' => [ 'Name of report', :sum ],
    'report-b2' => [ 'Name of report', :avg ],
  }
}.each_pair do |group_name, reports|
  group = DB[:groups][ name: group_name ]
  raise "ERROR: unknown report group '#{ group_name }'" if group.nil?

  reports.each_pair do |name, values|
    DB[:reports].insert group_id: group[:id], name: name, description: values.first, aggregate: values.last.to_s
  end
end

Add tasks to Rakefile:

% cat Rakefile
...
require 'graffable/migration_task'
Graffable::MigrationTask.new

require 'graffable/seed_task'
Graffable::SeedTask.new
...

Migrate database and load seed data:

% rake graffable:migrate:reset graffable:seed

Create config.ru and launch application:

% cat config.ru
require 'graffable'
run Graffable::App
% rackup

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request