Class: Eventifier::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/eventifier/tracker.rb

Instance Method Summary collapse

Constructor Details

#initialize(klasses, methods, options) ⇒ Tracker

Returns a new instance of Tracker.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/eventifier/tracker.rb', line 3

def initialize(klasses, methods, options)
  @klasses   = klasses
  methods    = methods.kind_of?(Array) ? methods : [methods]
  raise 'No events defined to track' if methods.compact.empty?

  User.class_eval {
    has_many :notifications, class_name: 'Eventifier::Notification'
  } unless User.respond_to?(:notifications)
  User.class_eval {
    has_one :notification_setting,
            class_name: 'Eventifier::NotificationSetting',
            dependent: :destroy
  } unless User.respond_to?(:notification_setting)



  # set up each class with an observer and relationships
  @klasses.each do |target_klass|
    Eventifier::TrackableClass.track target_klass, methods, options
  end
end