diff --git a/README.md b/README.md index ae67ca2..4b08d97 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ![Impressionist Logo](https://github.com/charlotte-ruby/impressionist/raw/master/logo.png) [![Build Status](https://secure.travis-ci.org/charlotte-ruby/impressionist.png?branch=master)](http://travis-ci.org/charlotte-ruby/impressionist) +[![Code Climate](https://codeclimate.com/github/charlotte-ruby/impressionist.png)](https://codeclimate.com/github/charlotte-ruby/impressionist) impressionist ============= @@ -224,9 +225,10 @@ Want to run the tests? Ok mummy Contributors ------------ -* [johnmcaliley](https://github.com/johnmcaliley) +* [johnmcaliley - creator](https://github.com/johnmcaliley) +* [Antonio C Nalesso - maintainer](https://github.com/nbit001) * [coryschires](https://github.com/coryschires) * [georgmittendorfer](https://github.com/georgmittendorfer) -* [Antonio C Nalesso](https://github.com/nbit001) + Copyright (c) 2011 John McAliley. See LICENSE.txt for further details. diff --git a/lib/impressionist/models/mongoid/impressionist/impressionable.rb b/lib/impressionist/models/mongoid/impressionist/impressionable.rb index 8ceb912..d770a79 100644 --- a/lib/impressionist/models/mongoid/impressionist/impressionable.rb +++ b/lib/impressionist/models/mongoid/impressionist/impressionable.rb @@ -4,28 +4,21 @@ module Impressionist # extends AS::Concern include Impressionist::IsImpressionable - ## TODO: Make it readable - - # Overides impressionist_count in order to provied - # mongoid compability + # Overides impressionist_count in order to provide mongoid compability def impressionist_count(options={}) - options. - reverse_merge!( - :filter=>:request_hash, - :start_date=>nil, - :end_date=>Time.now) - imps = options[:start_date].blank? ? - impressions : - impressions. - between(created_at: options[:start_date]..options[:end_date]) + # Uses these options as defaults unless overridden in options hash + options.reverse_merge!(:filter => :request_hash, :start_date => nil, :end_date => Time.now) - filter = options[:filter] + # 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]) - filter == :all ? - imps.count : - imps.where(filter.ne => nil). - distinct(filter).count + + # Count all distinct impressions unless the :all filter is provided + distinct = options[:filter] != :all + distinct ? imps.where(filter.ne => nil).distinct(filter).count : imps.count end end