Module: Impressionist::Impressionable

Extended by:
ActiveSupport::Concern
Includes:
IsImpressionable
Defined in:
app/models/impressionist/impressionable.rb,
lib/impressionist/models/mongoid/impressionist/impressionable.rb,
lib/impressionist/models/mongo_mapper/impressionist/impressionable.rb,
lib/impressionist/models/active_record/impressionist/impressionable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#impressionable?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'app/models/impressionist/impressionable.rb', line 56

def impressionable?
  true
end

#impressionist_count(options = {}) ⇒ Object

Overides impressionist_count in order to provide mongoid compability


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/impressionist/impressionable.rb', line 31

def impressionist_count(options={})
  # Uses these options as defaults unless overridden in options hash
  options.reverse_merge!(:filter => :request_hash, :start_date => nil, :end_date => Time.now)

  # If a start_date is provided, finds impressions between then and the end_date. Otherwise returns all impressions
  imps = options[:start_date].blank? ? impressions : impressions.where("created_at >= ? and created_at <= ?", options[:start_date], options[:end_date])

  if options[:message]
    imps = imps.where("impressions.message = ?", options[:message])
  end

  # Count all distinct impressions unless the :all filter is provided.
  distinct = options[:filter] != :all
  if Rails::VERSION::MAJOR >= 4
    distinct ? imps.select(options[:filter]).distinct.count : imps.count
  else
    distinct ? imps.count(options[:filter], :distinct => true) : imps.count
  end
end

#update_impressionist_counter_cacheObject


51
52
53
54
# File 'app/models/impressionist/impressionable.rb', line 51

def update_impressionist_counter_cache
  slave = Impressionist::UpdateCounters.new(self)
  slave.update
end