Chameleon

DESCRIPTION:

This is a Rails engine designed to make it super easy to expose data from your application as widgets for use with Geckoboard (geckoboard.com).

This works for Rails 3 and Rails 4 apps.

FEATURES:

This provides a generator to build widgets using a basic DSL syntax to describe the data to be exposed, and the settings for it to be exposed under, and also includes the controller/routing necessary to provide an endpoint for Geckoboard to retrieve the data to display on your dashboard.

Currently it supports the “number and optional secondary stat” (with optional display text), “line”, “pie”, “geckometer”, “rag” and “text” widget types.

SYNOPSIS:

Simply add to your Gemfile as follows:

gem 'chameleon'

Then run “bundle install” and once installed, you can run:

rails g chameleon:widget NAME TYPE

to generate a widget within “app/widgets”. For example, if you want to generate a widget that exposes the amount of users you have in your app currently:

rails g chameleon:widget users number_and_secondary

This will generate something similar to the following in “app/widgets/users_widget.rb”:

widget :users do
  key "3638c90ec12d5a59061ad7b78afcbd050e50b621"
  type "number_and_secondary"
  data do
  end
end

To implement your widget, you simply need to alter it to return the required data - for a “number_and_secondary” type of widget, it requires a hash containing a :value, and optionally, a :previous value to compare it to (such as user count as of yesterday, for example):

widget :users do
  key "3618c90ec02d5a57061ad7b78afcbb050e50b608"
  type "number_and_secondary"
  data do
    {
      :value => User.count,
      :previous => User.count(:conditions => "created_at < '#{1.day.ago.to_s(:db)}'")
    }
  end
end

You can then point Geckoboard at your widget, myapp/widgets/users?key=3618c90ec02d5a57061ad7b78afcbb050e50b608, and Geckoboard will then show the current user count, as well as the percentage difference compared to a day ago.

More documentation on the settings available for the widgets, as well as the different types of widgets, is available on the wiki (github.com/ejdraper/chameleon/wiki).

REQUIREMENTS:

A Rails 3 or Rails 4 application and a Geckoboard account.

INSTALL:

It’s best to add it to the Gemfile for your Rails 3 app, but if needed you can install the gem manually:

gem install chameleon

CONTRIBUTORS:

Elliott Draper

Tim Blair

Jared Armstrong

LICENSE:

Copyright 2013 Elliott Draper <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.