Module: Eventifier::EventTracking

Included in:
EventTracking
Defined in:
lib/eventifier/event_tracking.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.url_mappingsObject



35
36
37
# File 'lib/eventifier/event_tracking.rb', line 35

def self.url_mappings
  @url_mapppings ||= {}
end

Instance Method Details

#events_for(klass, *args, &block) ⇒ Object



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

def events_for(klass, *args, &block)
  @klasses = klass.kind_of?(Array) ? klass : [klass]

  options = args[0] || { }

  methods    = options.delete(:track_on)
  attributes = options.delete(:attributes)

  if block.nil?
    track_on methods, :attributes => attributes
  else
    instance_eval(&block)
  end

  @klasses.each { |klass| Eventifier.tracked_classes << klass }
  Eventifier.tracked_classes.uniq!
end

#notify(*args) ⇒ Object



25
26
27
# File 'lib/eventifier/event_tracking.rb', line 25

def notify(*args)
  Eventifier::Notifier.new @klasses, *args
end

#track_on(methods, options = {}) ⇒ Object



21
22
23
# File 'lib/eventifier/event_tracking.rb', line 21

def track_on(methods, options = {})
  Eventifier::Tracker.new @klasses, methods, options
end

#url(url_proc) ⇒ Object



29
30
31
32
33
# File 'lib/eventifier/event_tracking.rb', line 29

def url(url_proc)
  @klasses.each do |target_klass|
    Eventifier::EventTracking.url_mappings[target_klass.name.underscore.to_sym] = url_proc
  end
end