Sha256: dbf74d2cf7e040d9cd2dc66fc161c146c29565e163e6e90deeaf130a1c6b06f4

Contents?: true

Size: 973 Bytes

Versions: 12

Compression:

Stored size: 973 Bytes

Contents

module Impressionist
  module Impressionable

  # extends AS::Concern
  include Impressionist::IsImpressionable

    # Overides impressionist_count in order to provide mongoid compability
    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.between(created_at: options[:start_date]..options[:end_date])


      # Count all distinct impressions unless the :all filter is provided
      distinct = options[:filter] != :all
      distinct ? imps.where(options[:filter].ne => nil).distinct(options[:filter]).count : imps.count
    end

  end
end

Mongoid::Document.
send(:include, Impressionist::Impressionable)

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
impressionist-cody-2.0.0 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist-2.0.0 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist-1.6.1 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist-1.6.0 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist-1.5.2 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist2-1.5.5 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist2-1.5.4 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist2-1.5.3 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist2-1.5.1 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist-1.5.1 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist-1.4.13 lib/impressionist/models/mongoid/impressionist/impressionable.rb
impressionist-1.4.12 lib/impressionist/models/mongoid/impressionist/impressionable.rb