Introduction
Introduction Statistics Contact Development Disclaimer Help
renamed date_column_name and value_column_name to date_column and _value_column…
Log
Files
Refs
README
---
commit ad0c943f055c555e8eabdc7abfd976b793a8edde
parent 66d3c50585da6e9dc675beb88045319b8fee436e
Author: Marco Otte-Witte <[email protected]>
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 <[email protected]>
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(-)
---
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…
- # * <tt>:value_column_name</tt> - The name of the column that holds the …
- # * <tt>:aggregation</tt> - The aggregation to use (either :count or :su…
+ # * <tt>:date_column</tt> - The name of the date column on that the reco…
+ # * <tt>:value_column</tt> - The name of the column that holds the value…
+ # * <tt>:aggregation</tt> - The aggregation to use (either :count or :su…
# * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,…
# * <tt>:limit</tt> - The number of periods to get (see :grouping)
# * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o…
@@ -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_…
+ # reports_as_sparkline :activations, :date_column => :activated_at, :…
# reports_as_sparkline :total_users_report, :cumulate => true
- # reports_as_sparkline :rake, :aggregation => :sum, :value_column_nam…
+ # reports_as_sparkline :rake, :aggregation => :sum, :value_column => …
# end
def reports_as_sparkline(name, options = {})
(class << self; self; end).instance_eval do
diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sp…
@@ -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
diff --git a/lib/kvlr/reports_as_sparkline/report.rb b/lib/kvlr/reports_as_spar…
@@ -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, :group…
+ attr_reader :klass, :name, :date_column, :value_column, :grouping, :aggr…
# ==== Parameters
# * <tt>klass</tt> - The model the report works on (This is the class yo…
@@ -13,9 +13,9 @@ module Kvlr #:nodoc:
#
# ==== Options
#
- # * <tt>:date_column_name</tt> - The name of the date column on that the…
- # * <tt>:value_column_name</tt> - The name of the column that holds the …
- # * <tt>:aggregation</tt> - The aggregation to use (either :count or :su…
+ # * <tt>:date_column</tt> - The name of the date column on that the reco…
+ # * <tt>:value_column</tt> - The name of the column that holds the value…
+ # * <tt>:aggregation</tt> - The aggregation to use (either :count or :su…
# * <tt>:grouping</tt> - The period records are grouped on (:hour, :day,…
# * <tt>:limit</tt> - The number of periods to get (see :grouping)
# * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; o…
@@ -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[:aggrega…
+ @date_column = (options[:date_column] || 'created_at').to_s
+ @value_column = (options[:value_column] || (options[:aggregation] != :…
@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..…
end
- conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ') + @date_co…
+ conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ') + @date_co…
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,…
+ raise ArgumentError.new("Invalid option #{k}") unless [:limit,…
end
raise ArgumentError.new("Invalid aggregation #{options[:aggregat…
raise ArgumentError.new("Invalid grouping #{options[:grouping]}"…
- raise ArgumentError.new('The name of the column holding the valu…
+ raise ArgumentError.new('The name of the column holding the valu…
when :run
options.each_key do |k|
raise ArgumentError.new("Invalid option #{k}") unless [:limit,…
diff --git a/spec/other/cumulated_report_spec.rb b/spec/other/cumulated_report_…
@@ -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, :regis…
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
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 condit…
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
result[0][1].should == 3
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,…
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
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 condit…
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
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…
+ it 'should return conditions for date_column >= begin_at only when no cust…
begin_at = Time.now
@report.send(:setup_conditions, begin_at).should == ['created_at >= ?', …
end
- it 'should return conditions for date_column_name >= begin_at only when an…
+ it 'should return conditions for date_column >= begin_at only when an empt…
begin_at = Time.now
@report.send(:setup_conditions, begin_at, {}).should == ['created_at >= …
end
- it 'should return conditions for date_column_name >= begin_at only when an…
+ it 'should return conditions for date_column >= begin_at only when an empt…
begin_at = Time.now
@report.send(:setup_conditions, begin_at, []).should == ['created_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 })…
end
- it 'should raise an error if aggregation :sum is spesicied but no :value…
+ it 'should raise an error if aggregation :sum is spesicied but no :value…
lambda { @report.send(:ensure_valid_options, { :aggregation => :sum })…
end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.