Module: Boffin::Trackable

Defined in:
lib/boffin/trackable.rb

Overview

Can be included into a class that responds to #as_member, #to_i, or #to_s. It's recommended to use track to inject Trackable into a class. It provides the instance methods of Tracker scoped to the host class and its instances.

See README for more examples.

Examples:

class MyModel < ActiveRecord::Base
  include Boffin::Trackable
  boffin.hit_types = [:views, :likes]
end

# Then record hits to instances of your model
@my_model = MyModel.find(1)
@my_model.hit(:views)

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



21
22
23
# File 'lib/boffin/trackable.rb', line 21

def self.included(mod)
  mod.extend(ClassMethods)
end

Instance Method Details

#hit(type, opts = {}) ⇒ Hit

Returns:

See Also:



43
44
45
# File 'lib/boffin/trackable.rb', line 43

def hit(type, opts = {})
  self.class.boffin.hit(type, self, opts)
end

#hit_count(type, opts = {}) ⇒ Float

Returns:

  • (Float)

See Also:

  • Tracker#hit_count


49
50
51
# File 'lib/boffin/trackable.rb', line 49

def hit_count(type, opts = {})
  self.class.boffin.count(type, self, opts)
end