From c054fe6b02187b73f7a0f30e17a0df1767737883 Mon Sep 17 00:00:00 2001 From: jd pagano Date: Thu, 10 Oct 2013 16:29:46 -0400 Subject: [PATCH 1/4] Refactor impressionist_count method in impressionable.rb method to be more human readable --- app/models/impressionist/impressionable.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index 71579f6..c9159bc 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -24,15 +24,19 @@ module Impressionist end # end of ClassMethods - # ------------------------------------------ - # TODO: CLEAN UP, make it HUMAN readable def impressionist_count(options={}) - options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now) - imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and 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) + + # 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 - options[:filter] == :all ? imps.count : imps.select(options[:filter]).distinct.count + distinct ? imps.select(options[:filter]).distinct.count : imps.count else - options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) + distinct ? imps.count(options[:filter], :distinct => true) : imps.count end end From 2b0fc9e57276d8749497ae97a9e06adf699b4599 Mon Sep 17 00:00:00 2001 From: Antonio C Nalesso Moreira Date: Thu, 10 Oct 2013 23:06:30 +0100 Subject: [PATCH 2/4] Bump to 1.4.11 --- lib/impressionist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/impressionist/version.rb b/lib/impressionist/version.rb index 5df3c93..2d55d4a 100644 --- a/lib/impressionist/version.rb +++ b/lib/impressionist/version.rb @@ -1,3 +1,3 @@ module Impressionist - VERSION = "1.4.10" + VERSION = "1.4.11" end From b8719206ff881cd29e89c456b266dbaf51f290a9 Mon Sep 17 00:00:00 2001 From: jd pagano Date: Thu, 10 Oct 2013 19:31:57 -0400 Subject: [PATCH 3/4] Refactor override of impressionist_count for mongoid compatibility to fit the same style as the default AR version --- .../mongoid/impressionist/impressionable.rb | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) 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 From 15fbb76f8890c6f2e08fc4c0c43d146574b1497f Mon Sep 17 00:00:00 2001 From: John McAliley Date: Fri, 18 Oct 2013 16:32:15 -0400 Subject: [PATCH 4/4] added code climate and changes to contributors --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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.