From 8a62a733c107a33edee8cabc908c3ebc3b280e8b Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Tue, 11 Mar 2008 23:39:40 -0700 Subject: renamed strategy method to format - strategy (the method on scalar and attribute) is a complex double-dispatching scheme to format (to_sql) a scalar in the light of the particular attribute; that is, it casts strings to integers if the column is int, etc. --- lib/active_relation/sql.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/active_relation/sql.rb') diff --git a/lib/active_relation/sql.rb b/lib/active_relation/sql.rb index 99cfc66383..ff00223ce7 100644 --- a/lib/active_relation/sql.rb +++ b/lib/active_relation/sql.rb @@ -4,8 +4,8 @@ module ActiveRelation delegate :quote_table_name, :quote_column_name, :quote, :to => :engine end - # module Formatting Context / Strategy # unit test me!!! - class Strategy + # unit test me!!! + class Formatter attr_reader :engine include Quoting @@ -14,7 +14,7 @@ module ActiveRelation end end - class Projection < Strategy + class Projection < Formatter def attribute(relation_name, attribute_name, aliaz) "#{quote_table_name(relation_name)}.#{quote_column_name(attribute_name)}" + (aliaz ? " AS #{quote(aliaz.to_s)}" : "") end @@ -24,7 +24,7 @@ module ActiveRelation end end - class Predicate < Strategy + class Predicate < Formatter def attribute(relation_name, attribute_name, aliaz) "#{quote_table_name(relation_name)}.#{quote_column_name(attribute_name)}" end @@ -38,19 +38,19 @@ module ActiveRelation end end - class Selection < Strategy + class Selection < Formatter def scalar(scalar) scalar end end - class Relation < Strategy + class Relation < Formatter def select(select_sql, aliaz) select_sql end end - class Aggregation < Strategy + class Aggregation < Formatter def select(select_sql, aliaz) "(#{select_sql}) AS #{engine.quote_table_name(aliaz)}" end -- cgit v1.2.3