diff options
Diffstat (limited to 'lib/arel/relations/utilities')
-rw-r--r-- | lib/arel/relations/utilities/aggregation.rb | 40 | ||||
-rw-r--r-- | lib/arel/relations/utilities/compound.rb | 26 | ||||
-rw-r--r-- | lib/arel/relations/utilities/nil.rb | 10 | ||||
-rw-r--r-- | lib/arel/relations/utilities/recursion.rb | 13 |
4 files changed, 89 insertions, 0 deletions
diff --git a/lib/arel/relations/utilities/aggregation.rb b/lib/arel/relations/utilities/aggregation.rb new file mode 100644 index 0000000000..66150bff0a --- /dev/null +++ b/lib/arel/relations/utilities/aggregation.rb @@ -0,0 +1,40 @@ +module Arel + class Aggregation < Compound + include Recursion::BaseCase + + def initialize(relation) + @relation = relation + end + + def wheres + [] + end + + def table_sql(formatter = Sql::TableReference.new(relation)) + formatter.select relation.select_sql, self + end + + def attributes + @attributes ||= relation.attributes.collect(&:to_attribute).collect { |a| a.bind(self) } + end + + def name + relation.name + '_aggregation' + end + + def ==(other) + Aggregation === other and + self.relation == other.relation + end + end + + class Relation + def externalize + @externalized ||= aggregation?? Aggregation.new(self) : self + end + + def aggregation? + false + end + end +end
\ No newline at end of file diff --git a/lib/arel/relations/utilities/compound.rb b/lib/arel/relations/utilities/compound.rb new file mode 100644 index 0000000000..a77099e0de --- /dev/null +++ b/lib/arel/relations/utilities/compound.rb @@ -0,0 +1,26 @@ +module Arel + class Compound < Relation + attr_reader :relation + hash_on :relation + delegate :joins, :wheres, :join?, :inserts, :taken, + :skipped, :name, :aggregation?, :column_for, + :engine, :table, :table_sql, + :to => :relation + + def attributes + @attributes ||= relation.attributes.collect { |a| a.bind(self) } + end + + def wheres + @wheres ||= relation.wheres.collect { |w| w.bind(self) } + end + + def groupings + @groupings ||= relation.groupings.collect { |g| g.bind(self) } + end + + def orders + @orders ||= relation.orders.collect { |o| o.bind(self) } + end + end +end
\ No newline at end of file diff --git a/lib/arel/relations/utilities/nil.rb b/lib/arel/relations/utilities/nil.rb new file mode 100644 index 0000000000..2dcfb47233 --- /dev/null +++ b/lib/arel/relations/utilities/nil.rb @@ -0,0 +1,10 @@ +module Arel + class Nil < Relation + def table_sql(formatter = nil); '' end + def name; '' end + + def ==(other) + Nil === other + end + end +end
\ No newline at end of file diff --git a/lib/arel/relations/utilities/recursion.rb b/lib/arel/relations/utilities/recursion.rb new file mode 100644 index 0000000000..848b059507 --- /dev/null +++ b/lib/arel/relations/utilities/recursion.rb @@ -0,0 +1,13 @@ +module Arel + module Recursion + module BaseCase + def table + self + end + + def table_sql(formatter = Sql::TableReference.new(self)) + formatter.table self + end + end + end +end
\ No newline at end of file |