aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/utilities/compound.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra/relations/utilities/compound.rb')
-rw-r--r--lib/arel/algebra/relations/utilities/compound.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/arel/algebra/relations/utilities/compound.rb b/lib/arel/algebra/relations/utilities/compound.rb
new file mode 100644
index 0000000000..5e775618f1
--- /dev/null
+++ b/lib/arel/algebra/relations/utilities/compound.rb
@@ -0,0 +1,30 @@
+module Arel
+ class Compound < Relation
+ attr_reader :relation
+ delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?,
+ :column_for, :engine,
+ :to => :relation
+
+ [:attributes, :wheres, :groupings, :orders].each do |operation_name|
+ class_eval <<-OPERATION, __FILE__, __LINE__
+ def #{operation_name}
+ @#{operation_name} ||= relation.#{operation_name}.collect { |o| o.bind(self) }
+ end
+ OPERATION
+ end
+
+ def hash
+ @hash ||= :relation.hash
+ end
+
+ def eql?(other)
+ self == other
+ end
+
+ private
+
+ def arguments_from_block(relation, &block)
+ block_given?? [yield(relation)] : []
+ end
+ end
+end