aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO6
-rw-r--r--lib/active_relation/extensions/array.rb4
-rw-r--r--lib/active_relation/extensions/hash.rb2
-rw-r--r--lib/active_relation/extensions/object.rb4
-rw-r--r--lib/active_relation/predicates.rb2
-rw-r--r--lib/active_relation/primitives/attribute.rb8
-rw-r--r--lib/active_relation/primitives/expression.rb2
-rw-r--r--lib/active_relation/primitives/value.rb4
-rw-r--r--lib/active_relation/relations/deletion.rb2
-rw-r--r--lib/active_relation/relations/insertion.rb2
-rw-r--r--lib/active_relation/relations/relation.rb4
-rw-r--r--lib/active_relation/relations/update.rb2
12 files changed, 21 insertions, 21 deletions
diff --git a/TODO b/TODO
index 8425057d59..c3d5e07647 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,5 @@
todo:
-- remove to_sql logic from array and hash, push it into a strategy
+- remove to_sql logic from array and hash, push it into a formatter
- string passthrough:
:joins=>"INNER JOIN posts ON comments.post_id = posts.id"
:conditions=>"(`posts`.author_id = 1)",
@@ -25,7 +25,7 @@ todo:
- test relation, table reset
- cache expiry on write
- rewrite of querycache test in light of this
-- relation inclusion when given an array (1,2,3,4) should quote the elements using the appropriate quoting strategy taken from the attribute
+- relation inclusion when given an array (1,2,3,4) should quote the elements using the appropriate quoting formatter taken from the attribute
- descend on array, along with bind written in terms of it
- standardize quoting
- use strings everywhere, not symbols ?
@@ -67,6 +67,6 @@ done:
- hash custom matcher
- make session engine stuff follow laws of demeter - currently doing some odd method chaining? rethink who is responsible for what
- session just calls execute, passing in a connection; by default it gets a connection from the relation.
-- #strategy is now on value, attribute and relation; you must admit it's name is confusing given that e.g., relation already has a strategy (Sql::Relation) ... should it be called predicate strategy? operand1.to_sql(operand2.predicate) maybe prefer operand1.cast(operand2) or project or in light of
+- #formatter is now on value, attribute and relation; you must admit it's name is confusing given that e.g., relation already has a formatter (Sql::Relation) ... should it be called predicate formatter? operand1.to_sql(operand2.predicate) maybe prefer operand1.cast(operand2) or project or in light of
- renamed to #format: operand1.format(operand2)
- rename sql strategies
diff --git a/lib/active_relation/extensions/array.rb b/lib/active_relation/extensions/array.rb
index 3b4246fb1c..5e2981a4c5 100644
--- a/lib/active_relation/extensions/array.rb
+++ b/lib/active_relation/extensions/array.rb
@@ -3,7 +3,7 @@ class Array
Hash[*flatten]
end
- def to_sql(strategy = Sql::SelectExpression.new)
- strategy.array self
+ def to_sql(formatter = Sql::SelectExpression.new)
+ formatter.array self
end
end \ No newline at end of file
diff --git a/lib/active_relation/extensions/hash.rb b/lib/active_relation/extensions/hash.rb
index ae3e48146f..133eab1026 100644
--- a/lib/active_relation/extensions/hash.rb
+++ b/lib/active_relation/extensions/hash.rb
@@ -9,7 +9,7 @@ class Hash
end
end
- def to_sql(strategy = nil)
+ def to_sql(formatter = nil)
'(' +
inject([]) do |values, (key, value)|
values << key.format(value)
diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb
index 2682ed99fe..cd51543c91 100644
--- a/lib/active_relation/extensions/object.rb
+++ b/lib/active_relation/extensions/object.rb
@@ -3,8 +3,8 @@ class Object
ActiveRelation::Value.new(self, relation)
end
- def to_sql(strategy = nil)
- strategy.scalar self
+ def to_sql(formatter = nil)
+ formatter.scalar self
end
def metaclass
diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb
index 12ddd1b48d..98a966507f 100644
--- a/lib/active_relation/predicates.rb
+++ b/lib/active_relation/predicates.rb
@@ -24,7 +24,7 @@ module ActiveRelation
descend(&:qualify)
end
- def to_sql(strategy = nil)
+ def to_sql(formatter = nil)
"#{operand2.format(operand1)} #{predicate_sql} #{operand1.format(operand2)}"
end
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb
index f2c484cc59..fc857347fc 100644
--- a/lib/active_relation/primitives/attribute.rb
+++ b/lib/active_relation/primitives/attribute.rb
@@ -111,16 +111,16 @@ module ActiveRelation
end
include Expressions
- def to_sql(strategy = Sql::WhereCondition.new(engine))
- strategy.attribute prefix, name, self.alias
+ def to_sql(formatter = Sql::WhereCondition.new(engine))
+ formatter.attribute prefix, name, self.alias
end
def format(object)
- object.to_sql(strategy)
+ object.to_sql(formatter)
end
private
- def strategy
+ def formatter
Sql::Attribute.new(self)
end
diff --git a/lib/active_relation/primitives/expression.rb b/lib/active_relation/primitives/expression.rb
index 11aa558977..2df2888ba0 100644
--- a/lib/active_relation/primitives/expression.rb
+++ b/lib/active_relation/primitives/expression.rb
@@ -25,7 +25,7 @@ module ActiveRelation
end
include Transformations
- def to_sql(strategy = nil)
+ def to_sql(formatter = nil)
"#{function_sql}(#{attribute.to_sql})" + (@alias ? " AS #{quote_column_name(@alias)}" : '')
end
diff --git a/lib/active_relation/primitives/value.rb b/lib/active_relation/primitives/value.rb
index 096c876ecd..131610f2e9 100644
--- a/lib/active_relation/primitives/value.rb
+++ b/lib/active_relation/primitives/value.rb
@@ -6,8 +6,8 @@ module ActiveRelation
@value, @relation = value, relation
end
- def to_sql(strategy = Sql::WhereCondition.new(relation.engine))
- strategy.value value
+ def to_sql(formatter = Sql::WhereCondition.new(relation.engine))
+ formatter.value value
end
def format(object)
diff --git a/lib/active_relation/relations/deletion.rb b/lib/active_relation/relations/deletion.rb
index 0fcf523efe..1b94df8729 100644
--- a/lib/active_relation/relations/deletion.rb
+++ b/lib/active_relation/relations/deletion.rb
@@ -4,7 +4,7 @@ module ActiveRelation
@relation = relation
end
- def to_sql(strategy = nil)
+ def to_sql(formatter = nil)
[
"DELETE",
"FROM #{table_sql}",
diff --git a/lib/active_relation/relations/insertion.rb b/lib/active_relation/relations/insertion.rb
index 7a13bc06bb..bcf8e33e0a 100644
--- a/lib/active_relation/relations/insertion.rb
+++ b/lib/active_relation/relations/insertion.rb
@@ -6,7 +6,7 @@ module ActiveRelation
@relation, @record = relation, record
end
- def to_sql(strategy = nil)
+ def to_sql(formatter = nil)
[
"INSERT",
"INTO #{table_sql}",
diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb
index 039af61925..8c93f948f7 100644
--- a/lib/active_relation/relations/relation.rb
+++ b/lib/active_relation/relations/relation.rb
@@ -102,8 +102,8 @@ module ActiveRelation
false
end
- def to_sql(strategy = Sql::SelectStatement.new(engine))
- strategy.select [
+ def to_sql(formatter = Sql::SelectStatement.new(engine))
+ formatter.select [
"SELECT #{attributes.collect { |a| a.to_sql(Sql::SelectExpression.new(engine)) }.join(', ')}",
"FROM #{table_sql}",
(joins unless joins.blank? ),
diff --git a/lib/active_relation/relations/update.rb b/lib/active_relation/relations/update.rb
index a51f248866..dc88ea0362 100644
--- a/lib/active_relation/relations/update.rb
+++ b/lib/active_relation/relations/update.rb
@@ -6,7 +6,7 @@ module ActiveRelation
@relation, @assignments = relation, assignments
end
- def to_sql(strategy = nil)
+ def to_sql(formatter = nil)
[
"UPDATE #{table_sql} SET",
assignments.inject("") do |assignments, (attribute, value)|