replace more references to Report namespace with 'engine' method call

pull/6827/head
Tim Felgentreff 14 years ago
parent bd337d33df
commit 2e5d94800c
  1. 10
      app/models/report/filter/base.rb
  2. 1
      app/models/report/filter/no_filter.rb
  3. 2
      app/models/report/group_by/base.rb
  4. 1
      app/models/report/operator.rb
  5. 30
      app/models/report/query_utils.rb
  6. 9
      app/models/report/sql_statement.rb

@ -1,6 +1,8 @@
class Report::Filter
class Base < Report::Chainable
Report::Operator.load
include Report::CostQuery
engine::Operator.load
inherited_attribute :available_operators,
:list => true, :map => :to_operator,
@ -30,8 +32,8 @@ class Report::Filter
names.each do |name|
dont_inherit :available_operators if skip_inherited_operators.include? name
case name
when String, Report::Operator then operators << name.to_operator
when Symbol then operators.push(*Report::Operator.send(name))
when String, engine::Operator then operators << name.to_operator
when Symbol then operators.push(*engine::Operator.send(name))
else fail "dunno what to do with #{name.inspect}"
end
end
@ -93,7 +95,7 @@ class Report::Filter
end
def operator
(@operator || self.class.default_operator || Report::Operator.default_operator).to_operator
(@operator || self.class.default_operator || engine::Operator.default_operator).to_operator
end
def operator=(value)

@ -3,5 +3,6 @@ class Report::Filter::NoFilter < Report::Filter::Base
singleton
def sql_statement
raise NotImplementedError, "My subclass should have overwritten 'sql_statement'"
end
end

@ -37,7 +37,7 @@ class Report::GroupBy
def aggregation_mixin
sql_aggregation? ? SqlAggregation : RubyAggregation
end
end
def initialize(child = nil, optios = {})
super

@ -189,6 +189,7 @@ class Report::Operator
all[name.to_s] ||= super
end
#TODO: this should be inheritable by subclasses
def self.all
@@all_operators ||= {}
end

@ -1,6 +1,16 @@
module Report::QueryUtils
delegate :quoted_false, :quoted_true, :to => "ActiveRecord::Base.connection"
def self.included(base)
@includees ||= []
@includees << base
end
def self.send_to_all_includees(mod)
@includees ||= []
@includees.each {|i| i.send :include, mod }
end
##
# Subclass of Report to be used for constant lookup and such.
# It is considered public API to override this method i.e. in Tests.
@ -28,7 +38,21 @@ module Report::QueryUtils
# @param [#flatten] *values Ruby collection
# @return [String] SQL collection
def collection(*values)
"(#{values.flatten.map { |v| "'#{quote_string(v)}'" }.join ", "})"
if values.empty?
""
else
"(#{values.flatten.map { |v| "'#{quote_string(v)}'" }.join ", "})"
end
end
##
# Graceful, internationalized quoted string.
#
# @see quote_string
# @param [Object] str String to quote/translate
# @return [Object] Quoted, translated version
def quoted_label(ident)
"'#{quote_string l(ident)}'"
end
def quoted_date(date)
@ -74,6 +98,7 @@ module Report::QueryUtils
# @return [String] Field name.
def field_name_for(arg, default_table = nil)
return 'NULL' unless arg
return field_name_for(arg.keys.first, default_table) if arg.is_a? Hash
return arg if arg.is_a? String and arg =~ /\.| |\(.*\)/
return table_name_for(arg.first || default_table) + '.' << arg.last.to_s if arg.is_a? Array and arg.size == 2
return arg.to_s unless default_table
@ -87,10 +112,11 @@ module Report::QueryUtils
# @param [Object] statement Not sanitized statement.
# @return [String] Sanitized statement.
def sanitize_sql_for_conditions(statement)
Report.send :sanitize_sql_for_conditions, statement
engine.send :sanitize_sql_for_conditions, statement
end
##
# FIXME: This is redmine
# Generates string representation for a currency.
#
# @see CostRate.clean_currency

@ -150,6 +150,11 @@ class Report::SqlStatement
end
end
def default_select(value = nil)
@default_select = value if value
@default_select ||= ["*"]
end
##
# @overload select
# @return [Array<String>] All fields/statements for select part
@ -165,7 +170,7 @@ class Report::SqlStatement
# @param [Array, Hash, String, Symbol, SqlStatement] fields Fields to add to select part
# @return [Array<String>] All fields/statements for select part
def select(*fields)
return(@select || ["*"]) if fields.empty?
return(@select || default_select) if fields.empty?
returning(@select ||= []) do
@sql = nil
fields.each do |f|
@ -176,7 +181,7 @@ class Report::SqlStatement
end
when Hash then select f.map { |k,v| "#{field_name_for v} as #{field_name_for k}" }
when String, Symbol then @select << field_name_for(f)
when Report::SqlStatement then @select << f.to_s
when engine::SqlStatement then @select << f.to_s
else raise ArgumentError, "cannot handle #{f.inspect}"
end
end

Loading…
Cancel
Save