renamed date_column_name and value_column_name to date_column and _value_column - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit ad0c943f055c555e8eabdc7abfd976b793a8edde
 (DIR) parent 66d3c50585da6e9dc675beb88045319b8fee436e
 (HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       Date:   Tue, 13 Jan 2009 19:15:36 +0800
       
       renamed date_column_name and value_column_name to date_column and _value_column
       
       Signed-off-by: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       Diffstat:
         M lib/kvlr/reports_as_sparkline.rb    |      10 +++++-----
         M lib/kvlr/reports_as_sparkline/grou… |      38 ++++++++++++++++----------------
         M lib/kvlr/reports_as_sparkline/repo… |      24 ++++++++++++------------
         M spec/other/cumulated_report_spec.rb |       4 ++--
         M spec/other/report_spec.rb           |      16 ++++++++--------
       
       5 files changed, 46 insertions(+), 46 deletions(-)
       ---
 (DIR) diff --git a/lib/kvlr/reports_as_sparkline.rb b/lib/kvlr/reports_as_sparkline.rb
       @@ -16,9 +16,9 @@ module Kvlr #:nodoc:
              #
              # ==== Options
              #
       -      # * <tt>:date_column_name</tt> - The name of the date column on that the records are aggregated
       -      # * <tt>:value_column_name</tt> - The name of the column that holds the value to sum for aggregation :sum
       -      # * <tt>:aggregation</tt> - The aggregation to use (either :count or :sum); when using :sum, :value_column_name must also be specified
       +      # * <tt>:date_column</tt> - The name of the date column on that the records are aggregated
       +      # * <tt>:value_column</tt> - The name of the column that holds the value to sum for aggregation :sum
       +      # * <tt>:aggregation</tt> - The aggregation to use (either :count or :sum); when using :sum, :value_column must also be specified
              # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day, :week, :month)
              # * <tt>:limit</tt> - The number of periods to get (see :grouping)
              # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; only records that match there conditions are reported on
       @@ -31,9 +31,9 @@ module Kvlr #:nodoc:
              #  end
              #  class User < ActiveRecord::Base
              #    reports_as_sparkline :registrations, :operation => :count
       -      #    reports_as_sparkline :activations, :date_column_name => :activated_at, :operation => :count
       +      #    reports_as_sparkline :activations, :date_column => :activated_at, :operation => :count
              #    reports_as_sparkline :total_users_report, :cumulate => true
       -      #    reports_as_sparkline :rake, :aggregation => :sum, :value_column_name => :profile_visits
       +      #    reports_as_sparkline :rake, :aggregation => :sum, :value_column => :profile_visits
              #  end
              def reports_as_sparkline(name, options = {})
                (class << self; self; end).instance_eval do
 (DIR) diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sparkline/grouping.rb
       @@ -39,55 +39,55 @@ module Kvlr #:nodoc:
                end
              end
        
       -      def to_sql(date_column_name) #:nodoc:
       +      def to_sql(date_column) #:nodoc:
                return case ActiveRecord::Base.connection.class.to_s
                  when 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
       -            mysql_format(date_column_name)
       +            mysql_format(date_column)
                  when 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
       -            sqlite_format(date_column_name)
       +            sqlite_format(date_column)
                  when 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
       -            postgresql_format(date_column_name)
       +            postgresql_format(date_column)
                end
              end
        
              private
        
       -        def mysql_format(date_column_name)
       +        def mysql_format(date_column)
                  return case @identifier
                    when :hour
       -              "DATE_FORMAT(#{date_column_name}, '%Y/%m/%d/%H')"
       +              "DATE_FORMAT(#{date_column}, '%Y/%m/%d/%H')"
                    when :day
       -              "DATE_FORMAT(#{date_column_name}, '%Y/%m/%d')"
       +              "DATE_FORMAT(#{date_column}, '%Y/%m/%d')"
                    when :week
       -              "DATE_FORMAT(#{date_column_name}, '%Y/%u')"
       +              "DATE_FORMAT(#{date_column}, '%Y/%u')"
                    when :month
       -              "DATE_FORMAT(#{date_column_name}, '%Y/%m')"
       +              "DATE_FORMAT(#{date_column}, '%Y/%m')"
                  end
                end
        
       -        def sqlite_format(date_column_name)
       +        def sqlite_format(date_column)
                  return case @identifier
                    when :hour
       -              "strftime('%Y/%m/%d/%H', #{date_column_name})"
       +              "strftime('%Y/%m/%d/%H', #{date_column})"
                    when :day
       -              "strftime('%Y/%m/%d', #{date_column_name})"
       +              "strftime('%Y/%m/%d', #{date_column})"
                    when :week
       -              "strftime('%Y/%W', #{date_column_name})"
       +              "strftime('%Y/%W', #{date_column})"
                    when :month
       -              "strftime('%Y/%m', #{date_column_name})"
       +              "strftime('%Y/%m', #{date_column})"
                  end
                end
        
       -        def postgresql_format(date_column_name)
       +        def postgresql_format(date_column)
                  return case @identifier
                    when :hour
       -              "date_trunc('hour', #{date_column_name})"
       +              "date_trunc('hour', #{date_column})"
                    when :day
       -              "date_trunc('day', #{date_column_name})"
       +              "date_trunc('day', #{date_column})"
                    when :week
       -              "date_trunc('week', #{date_column_name})"
       +              "date_trunc('week', #{date_column})"
                    when :month
       -              "date_trunc('month', #{date_column_name})"
       +              "date_trunc('month', #{date_column})"
                  end
                end
        
 (DIR) diff --git a/lib/kvlr/reports_as_sparkline/report.rb b/lib/kvlr/reports_as_sparkline/report.rb
       @@ -5,7 +5,7 @@ module Kvlr #:nodoc:
            # The Report class that does all the data retrieval and calculations
            class Report
        
       -      attr_reader :klass, :name, :date_column_name, :value_column_name, :grouping, :aggregation
       +      attr_reader :klass, :name, :date_column, :value_column, :grouping, :aggregation
        
              # ==== Parameters
              # * <tt>klass</tt> - The model the report works on (This is the class you invoke Kvlr::ReportsAsSparkline::ClassMethods#reports_as_sparkline on)
       @@ -13,9 +13,9 @@ module Kvlr #:nodoc:
              #
              # ==== Options
              #
       -      # * <tt>:date_column_name</tt> - The name of the date column on that the records are aggregated
       -      # * <tt>:value_column_name</tt> - The name of the column that holds the value to sum for aggregation :sum
       -      # * <tt>:aggregation</tt> - The aggregation to use (either :count or :sum); when using :sum, :value_column_name must also be specified
       +      # * <tt>:date_column</tt> - The name of the date column on that the records are aggregated
       +      # * <tt>:value_column</tt> - The name of the column that holds the value to sum for aggregation :sum
       +      # * <tt>:aggregation</tt> - The aggregation to use (either :count or :sum); when using :sum, :value_column must also be specified
              # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day, :week, :month)
              # * <tt>:limit</tt> - The number of periods to get (see :grouping)
              # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; only records that match there conditions are reported on
       @@ -23,8 +23,8 @@ module Kvlr #:nodoc:
                ensure_valid_options(options)
                @klass             = klass
                @name              = name
       -        @date_column_name  = (options[:date_column_name] || 'created_at').to_s
       -        @value_column_name = (options[:value_column_name] || (options[:aggregation] != :sum ? 'id' : name)).to_s
       +        @date_column  = (options[:date_column] || 'created_at').to_s
       +        @value_column = (options[:value_column] || (options[:aggregation] != :sum ? 'id' : name)).to_s
                @aggregation       = options[:aggregation] || :count
                @grouping          = Grouping.new(options[:grouping] || :day)
                @options = {
       @@ -53,10 +53,10 @@ module Kvlr #:nodoc:
                def read_data(begin_at, conditions = []) #:nodoc:
                  conditions = setup_conditions(begin_at, conditions)
                  @klass.send(@aggregation,
       -            @value_column_name,
       +            @value_column,
                    :conditions => conditions,
       -            :group => @grouping.to_sql(@date_column_name),
       -            :order => "#{@grouping.to_sql(@date_column_name)} DESC"
       +            :group => @grouping.to_sql(@date_column),
       +            :order => "#{@grouping.to_sql(@date_column)} DESC"
                  )
                end
        
       @@ -67,7 +67,7 @@ module Kvlr #:nodoc:
                  elsif custom_conditions.size > 0
                    conditions = [(custom_conditions[0] || ''), *custom_conditions[1..-1]]
                  end
       -          conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ') + @date_column_name.to_s} >= ?"
       +          conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ') + @date_column.to_s} >= ?"
                  conditions << begin_at
                end
        
       @@ -75,11 +75,11 @@ module Kvlr #:nodoc:
                  case context
                    when :initialize
                      options.each_key do |k|
       -                raise ArgumentError.new("Invalid option #{k}") unless [:limit, :aggregation, :grouping, :date_column_name, :value_column_name, :conditions].include?(k)
       +                raise ArgumentError.new("Invalid option #{k}") unless [:limit, :aggregation, :grouping, :date_column, :value_column, :conditions].include?(k)
                      end
                      raise ArgumentError.new("Invalid aggregation #{options[:aggregation]}") if options[:aggregation] && ![:count, :sum].include?(options[:aggregation])
                      raise ArgumentError.new("Invalid grouping #{options[:grouping]}") if options[:grouping] && ![:hour, :day, :week, :month].include?(options[:grouping])
       -              raise ArgumentError.new('The name of the column holding the value to sum has to be specified for aggregation :sum') if options[:aggregation] == :sum && !options.key?(:value_column_name)
       +              raise ArgumentError.new('The name of the column holding the value to sum has to be specified for aggregation :sum') if options[:aggregation] == :sum && !options.key?(:value_column)
                    when :run
                      options.each_key do |k|
                        raise ArgumentError.new("Invalid option #{k}") unless [:limit, :conditions].include?(k)
 (DIR) diff --git a/spec/other/cumulated_report_spec.rb b/spec/other/cumulated_report_spec.rb
       @@ -59,7 +59,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do
                end
        
                it 'should return correct data for aggregation :sum' do
       -          @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column_name => :profile_visits, :limit => 10)
       +          @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column => :profile_visits, :limit => 10)
                  result = @report.run()
        
                  result[0][1].should == 6
       @@ -79,7 +79,7 @@ describe Kvlr::ReportsAsSparkline::CumulatedReport do
                end
        
                it 'should return correct data for aggregation :sum when custom conditions are specified' do
       -          @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column_name => :profile_visits, :limit => 10)
       +          @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column => :profile_visits, :limit => 10)
                  result = @report.run(:conditions => ['login IN (?)', ['test 1', 'test 2']])
        
                  result[0][1].should == 3
 (DIR) diff --git a/spec/other/report_spec.rb b/spec/other/report_spec.rb
       @@ -47,7 +47,7 @@ describe Kvlr::ReportsAsSparkline::Report do
                end
        
                it 'should return correct data for aggregation :sum' do
       -          @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column_name => :profile_visits, :limit => 10)
       +          @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column => :profile_visits, :limit => 10)
                  result = @report.run().to_a
        
                  result[0][1].should == 0
       @@ -67,7 +67,7 @@ describe Kvlr::ReportsAsSparkline::Report do
                end
        
                it 'should return correct data for aggregation :sum when custom conditions are specified' do
       -          @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column_name => :profile_visits, :limit => 10)
       +          @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :aggregation => :sum, :grouping => grouping, :value_column => :profile_visits, :limit => 10)
                  result = @report.run(:conditions => ['login IN (?)', ['test 1', 'test 2']]).to_a
        
                  result[0][1].should == 0
       @@ -109,19 +109,19 @@ describe Kvlr::ReportsAsSparkline::Report do
        
          describe '.setup_conditions' do
        
       -    it 'should return conditions for date_column_name >= begin_at only when no custom conditions are specified' do
       +    it 'should return conditions for date_column >= begin_at only when no custom conditions are specified' do
              begin_at = Time.now
        
              @report.send(:setup_conditions, begin_at).should == ['created_at >= ?', begin_at]
            end
        
       -    it 'should return conditions for date_column_name >= begin_at only when an empty Hash of custom conditions is specified' do
       +    it 'should return conditions for date_column >= begin_at only when an empty Hash of custom conditions is specified' do
              begin_at = Time.now
        
              @report.send(:setup_conditions, begin_at, {}).should == ['created_at >= ?', begin_at]
            end
        
       -    it 'should return conditions for date_column_name >= begin_at only when an empty Array of custom conditions is specified' do
       +    it 'should return conditions for date_column >= begin_at only when an empty Array of custom conditions is specified' do
              begin_at = Time.now
        
              @report.send(:setup_conditions, begin_at, []).should == ['created_at >= ?', begin_at]
       @@ -176,8 +176,8 @@ describe Kvlr::ReportsAsSparkline::Report do
                    :limit             => 100,
                    :aggregation       => :count,
                    :grouping          => :day,
       -            :date_column_name  => :created_at,
       -            :value_column_name => :id,
       +            :date_column  => :created_at,
       +            :value_column => :id,
                    :conditions        => []
                  })
                }.should_not raise_error(ArgumentError)
       @@ -195,7 +195,7 @@ describe Kvlr::ReportsAsSparkline::Report do
                lambda { @report.send(:ensure_valid_options, { :grouping => :decade }) }.should raise_error(ArgumentError)
              end
        
       -      it 'should raise an error if aggregation :sum is spesicied but no :value_column_name' do
       +      it 'should raise an error if aggregation :sum is spesicied but no :value_column' do
                lambda { @report.send(:ensure_valid_options, { :aggregation => :sum }) }.should raise_error(ArgumentError)
              end