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)


48
49
50
# File 'app/models/impressionist/impressionable.rb', line 48

def impressionable?
  true
end

#impressionist_count(options = {}) ⇒ Object

Overides impressionist_count in order to provide mongoid compability



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/impressionist/impressionable.rb', line 27

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])

  # 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



43
44
45
46
# File 'app/models/impressionist/impressionable.rb', line 43

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