aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-17 13:58:29 -0400
committerBryan Helmkamp <bryan@brynary.com>2009-05-17 13:58:29 -0400
commit2bbf8ca9d2af3ea959a21c3729b4894bc31f088b (patch)
treed28994667dbebe135cc7c43d3948a5e5d968f214 /lib/arel/relations
parent49d119ae84bbb7cd180ca855cf48997dc731554c (diff)
downloadrails-2bbf8ca9d2af3ea959a21c3729b4894bc31f088b.tar.gz
rails-2bbf8ca9d2af3ea959a21c3729b4894bc31f088b.tar.bz2
rails-2bbf8ca9d2af3ea959a21c3729b4894bc31f088b.zip
reorganized call
Conflicts: doc/TODO lib/arel/relations/relation.rb lib/arel/relations/writes/delete.rb lib/arel/relations/writes/insert.rb lib/arel/relations/writes/update.rb lib/arel/session.rb spec/arel/unit/relations/delete_spec.rb spec/arel/unit/relations/insert_spec.rb spec/arel/unit/relations/relation_spec.rb spec/arel/unit/relations/update_spec.rb spec/arel/unit/session/session_spec.rb
Diffstat (limited to 'lib/arel/relations')
-rw-r--r--lib/arel/relations/array.rb19
-rw-r--r--lib/arel/relations/relation.rb9
-rw-r--r--lib/arel/relations/writes/delete.rb4
-rw-r--r--lib/arel/relations/writes/insert.rb4
-rw-r--r--lib/arel/relations/writes/update.rb4
5 files changed, 27 insertions, 13 deletions
diff --git a/lib/arel/relations/array.rb b/lib/arel/relations/array.rb
new file mode 100644
index 0000000000..dac65abbc2
--- /dev/null
+++ b/lib/arel/relations/array.rb
@@ -0,0 +1,19 @@
+module Arel
+ class Array < Relation
+ include Recursion::BaseCase
+
+ def initialize(array, attribute_names)
+ @array, @attribute_names = array, attribute_names
+ end
+
+ def attributes
+ @attributes ||= @attribute_names.collect do |name|
+ Attribute.new(self, name.to_sym)
+ end
+ end
+
+ def call(connection = nil)
+ @array.collect { |row| attributes.zip(row).to_hash }
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index 5d2c336a15..ef295dfdd7 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -32,13 +32,8 @@ module Arel
"IN"
end
- def call(connection = engine)
- results = connection.execute(to_sql)
- rows = []
- results.each do |row|
- rows << attributes.zip(row).to_hash
- end
- rows
+ def call
+ engine.read(self)
end
def bind(relation)
diff --git a/lib/arel/relations/writes/delete.rb b/lib/arel/relations/writes/delete.rb
index b1ff3bef27..0a04454e7f 100644
--- a/lib/arel/relations/writes/delete.rb
+++ b/lib/arel/relations/writes/delete.rb
@@ -12,8 +12,8 @@ module Arel
].compact.join("\n")
end
- def call(connection = engine)
- connection.delete(to_sql)
+ def call
+ engine.delete(self)
end
end
end
diff --git a/lib/arel/relations/writes/insert.rb b/lib/arel/relations/writes/insert.rb
index d579ad06d0..d05bd9cdc8 100644
--- a/lib/arel/relations/writes/insert.rb
+++ b/lib/arel/relations/writes/insert.rb
@@ -16,8 +16,8 @@ module Arel
].join("\n")
end
- def call(connection = engine)
- connection.insert(to_sql)
+ def call
+ engine.create(self)
end
end
end
diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb
index 2e90de3a52..fd0aadb479 100644
--- a/lib/arel/relations/writes/update.rb
+++ b/lib/arel/relations/writes/update.rb
@@ -18,8 +18,8 @@ module Arel
].join("\n")
end
- def call(connection = engine)
- connection.update(to_sql)
+ def call
+ engine.update(self)
end
end
end