Module: ActsAsAppstatsable::ClassMethods

Defined in:
lib/appstats/acts_as_appstatsable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_appstatsable(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/appstats/acts_as_appstatsable.rb', line 9

def acts_as_appstatsable(options = {})
  self.cattr_accessor :appstats_after_create, :appstats_after_destroy, :appstats_after_update
  
  class_eval <<-EOV
     include ActsAsAppstatsable::InstanceMethods

     after_create :track_create
     after_destroy :track_destroy
     after_update :track_update
  EOV
  
  acts_as_appstatsable_options(options)
end

#acts_as_appstatsable_options(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/appstats/acts_as_appstatsable.rb', line 23

def acts_as_appstatsable_options(options = {})
  if !options[:only].nil?
    self.appstats_after_create = options[:only].include?(:create)
    self.appstats_after_destroy = options[:only].include?(:destroy)
    self.appstats_after_update = options[:only].include?(:update)
  elsif !options[:except].nil?
    self.appstats_after_create = !options[:except].include?(:create)
    self.appstats_after_destroy = !options[:except].include?(:destroy)
    self.appstats_after_update = !options[:except].include?(:update)
  else
    self.appstats_after_create = true
    self.appstats_after_destroy = true
    self.appstats_after_update = true
  end      
end