Module: Boffin

Defined in:
lib/boffin.rb,
lib/boffin/hit.rb,
lib/boffin/utils.rb,
lib/boffin/config.rb,
lib/boffin/tracker.rb,
lib/boffin/version.rb,
lib/boffin/keyspace.rb,
lib/boffin/trackable.rb

Overview

Boffin is a library for tracking hits to things in your Ruby application. Things can be IDs of records in a database, strings representing tags or topics, URLs of webpages, names of places, whatever you desire. Boffin is able to provide lists of those things based on most hits, least hits, it can even report on weighted combinations of different types of hits.

Refer to the README for further information and examples.

Defined Under Namespace

Modules: Trackable, Utils Classes: Config, Hit, Keyspace, Tracker, UndefinedHitTypeError

Constant Summary collapse

NIL_SESSION_MEMBER =

The member to use when no session identifier is available for unique hit tracking

'boffin:nilsession'
INTERVAL_FORMATS =

The way Time should be formatted for each interval type

{
:hours  => '%F-%H',
:days   => '%F',
:months => '%Y-%m' }
INTERVAL_TYPES =

Different interval types

INTERVAL_FORMATS.keys
VERSION =

Version of this Boffin release

'1.0.0'

Class Method Summary collapse

Class Method Details

.config(opts = {}) {|Config.new| ... } ⇒ Config

Set or get the default Config instance

Examples:

Getting the default config instance

Boffin.config

Setting the default config instance with a block

Boffin.config do |conf|
  conf.namespace = 'something:special'
end

Setting the default config instance with a Hash

Boffin.config(namespace: 'something:cool')

Parameters:

Yields:

Returns:

  • (Config)

    the default Config instance



52
53
54
# File 'lib/boffin.rb', line 52

def self.config(opts = {}, &block)
  @config ||= Config.new(opts, &block)
end

.track(class_or_ns, hit_types = []) ⇒ Tracker

Creates a new Tracker instance. If passed a class, Trackable is injected into it.

Examples:

Tracking an ActiveRecord model

Boffin.track(MyModel, [:views, :likes])

# This does the same thing:
class MyModel
  include Boffin::Tracker
  boffin.hit_types = [:views, :likes]
end

Creating a tracker without fancy injecting-ness

ThingsTracker = Boffin.track(:things)

# This does the same thing:
ThingsTracker = Boffin::Tracker.new(:things)

Parameters:

  • class_or_ns (Class, Symbol)

    A class or symbol to use as a namespace for the Tracker

  • hit_types (optional Array <Symbol>) (defaults to: [])

    A list of valid hit types for the Tracker

Returns:



76
77
78
79
80
81
82
83
84
85
# File 'lib/boffin.rb', line 76

def self.track(class_or_ns, hit_types = [])
  case class_or_ns
  when String, Symbol
    Tracker.new(class_or_ns, hit_types)
  else
    class_or_ns.send(:include, Trackable)
    class_or_ns.boffin.hit_types = hit_types
    class_or_ns.boffin
  end
end