diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-10 21:54:09 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-10 21:54:09 -0800 |
commit | dbdd86c689e962641d98ed0474a60d401582eac9 (patch) | |
tree | b606854e4e803ce3410ca5edf8a795dc9b184ac1 | |
parent | 45b6111c2961e018df87fe2230caf1d5a14f2aee (diff) | |
download | rails-dbdd86c689e962641d98ed0474a60d401582eac9.tar.gz rails-dbdd86c689e962641d98ed0474a60d401582eac9.tar.bz2 rails-dbdd86c689e962641d98ed0474a60d401582eac9.zip |
renamed files, removed _relation suffix
-rw-r--r-- | lib/active_relation.rb | 22 | ||||
-rw-r--r-- | lib/active_relation/relations/compound_relation.rb | 9 | ||||
-rw-r--r-- | lib/active_relation/relations/deletion_relation.rb | 17 | ||||
-rw-r--r-- | lib/active_relation/relations/insertion_relation.rb | 25 | ||||
-rw-r--r-- | lib/active_relation/relations/join_relation.rb | 45 | ||||
-rw-r--r-- | lib/active_relation/relations/order_relation.rb | 19 | ||||
-rw-r--r-- | lib/active_relation/relations/projection_relation.rb | 19 | ||||
-rw-r--r-- | lib/active_relation/relations/range_relation.rb | 23 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 111 | ||||
-rw-r--r-- | lib/active_relation/relations/rename_relation.rb | 38 | ||||
-rw-r--r-- | lib/active_relation/relations/selection_relation.rb | 25 | ||||
-rw-r--r-- | lib/active_relation/relations/table_relation.rb | 35 |
12 files changed, 11 insertions, 377 deletions
diff --git a/lib/active_relation.rb b/lib/active_relation.rb index 3f277df1a5..61235a5ae8 100644 --- a/lib/active_relation.rb +++ b/lib/active_relation.rb @@ -6,18 +6,18 @@ require 'activerecord' require 'active_relation/sql_builder' -require 'active_relation/relations/relation' -require 'active_relation/relations/compound_relation' -require 'active_relation/relations/table_relation' -require 'active_relation/relations/join_relation' +require 'active_relation/relations/base' +require 'active_relation/relations/compound' +require 'active_relation/relations/table' +require 'active_relation/relations/join' require 'active_relation/relations/attribute' -require 'active_relation/relations/projection_relation' -require 'active_relation/relations/selection_relation' -require 'active_relation/relations/order_relation' -require 'active_relation/relations/range_relation' -require 'active_relation/relations/rename_relation' -require 'active_relation/relations/deletion_relation' -require 'active_relation/relations/insertion_relation' +require 'active_relation/relations/projection' +require 'active_relation/relations/selection' +require 'active_relation/relations/order' +require 'active_relation/relations/range' +require 'active_relation/relations/rename' +require 'active_relation/relations/deletion' +require 'active_relation/relations/insertion' require 'active_relation/predicates' diff --git a/lib/active_relation/relations/compound_relation.rb b/lib/active_relation/relations/compound_relation.rb deleted file mode 100644 index 442224a011..0000000000 --- a/lib/active_relation/relations/compound_relation.rb +++ /dev/null @@ -1,9 +0,0 @@ -module ActiveRelation - module Relations - class Compound < Base - attr_reader :relation - - delegate :attributes, :attribute, :joins, :selects, :orders, :table, :inserts, :limit, :offset, :to => :relation - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/deletion_relation.rb b/lib/active_relation/relations/deletion_relation.rb deleted file mode 100644 index f218d9da6d..0000000000 --- a/lib/active_relation/relations/deletion_relation.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ActiveRelation - module Relations - class Deletion < Compound - def initialize(relation) - @relation = relation - end - - def to_sql(options = {}) - [ - "DELETE", - "FROM #{quote_table_name(table)}", - ("WHERE #{selects.collect(&:to_sql).join('\n\tAND ')}" unless selects.blank?) - ].compact.join("\n") - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/insertion_relation.rb b/lib/active_relation/relations/insertion_relation.rb deleted file mode 100644 index a0042a18a5..0000000000 --- a/lib/active_relation/relations/insertion_relation.rb +++ /dev/null @@ -1,25 +0,0 @@ -module ActiveRelation - module Relations - class Insertion < Compound - attr_reader :record - - def initialize(relation, record) - @relation, @record = relation, record - end - - def to_sql(options = {}) - [ - "INSERT", - "INTO #{quote_table_name(table)}", - "(#{record.keys.collect(&:to_sql).join(', ')})", - "VALUES #{inserts.collect(&:to_sql).join(', ')}" - ].join("\n") - end - - protected - def inserts - relation.inserts + [record] - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/join_relation.rb b/lib/active_relation/relations/join_relation.rb deleted file mode 100644 index 1bd1439dd6..0000000000 --- a/lib/active_relation/relations/join_relation.rb +++ /dev/null @@ -1,45 +0,0 @@ -module ActiveRelation - module Relations - class Join < Base - attr_reader :join_sql, :relation1, :relation2, :predicates - - def initialize(join_sql, relation1, relation2, *predicates) - @join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates - end - - def ==(other) - predicates == other.predicates and - ((relation1 == other.relation1 and relation2 == other.relation2) or - (relation2 == other.relation1 and relation1 == other.relation2)) - end - - def qualify - Join.new(join_sql, relation1.qualify, relation2.qualify, *predicates.collect(&:qualify)) - end - - protected - def joins - [relation1.joins, relation2.joins, join].compact.join(" ") - end - - def selects - relation1.send(:selects) + relation2.send(:selects) - end - - def attributes - relation1.attributes + relation2.attributes - end - - def attribute(name) - relation1[name] || relation2[name] - end - - delegate :table, :to => :relation1 - - private - def join - "#{join_sql} #{quote_table_name(relation2.table)} ON #{predicates.collect { |p| p.to_sql(:quote => false) }.join(' AND ')}" - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/order_relation.rb b/lib/active_relation/relations/order_relation.rb deleted file mode 100644 index 99ff939528..0000000000 --- a/lib/active_relation/relations/order_relation.rb +++ /dev/null @@ -1,19 +0,0 @@ -module ActiveRelation - module Relations - class Order < Compound - attr_reader :relation, :orders - - def initialize(relation, *orders) - @relation, @orders = relation, orders - end - - def ==(other) - relation == other.relation and orders.eql?(other.orders) - end - - def qualify - Order.new(relation.qualify, *orders.collect { |o| o.qualify }) - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/projection_relation.rb b/lib/active_relation/relations/projection_relation.rb deleted file mode 100644 index b30c76898d..0000000000 --- a/lib/active_relation/relations/projection_relation.rb +++ /dev/null @@ -1,19 +0,0 @@ -module ActiveRelation - module Relations - class Projection < Compound - attr_reader :relation, :attributes - - def initialize(relation, *attributes) - @relation, @attributes = relation, attributes - end - - def ==(other) - relation == other.relation and attributes.eql?(other.attributes) - end - - def qualify - Projection.new(relation.qualify, *attributes.collect(&:qualify)) - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/range_relation.rb b/lib/active_relation/relations/range_relation.rb deleted file mode 100644 index d7e08efa06..0000000000 --- a/lib/active_relation/relations/range_relation.rb +++ /dev/null @@ -1,23 +0,0 @@ -module ActiveRelation - module Relations - class Range < Compound - attr_reader :range - - def initialize(relation, range) - @relation, @range = relation, range - end - - def ==(other) - relation == other.relation and range == other.range - end - - def limit - range.end - range.begin + 1 - end - - def offset - range.begin - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb deleted file mode 100644 index c4a887eecd..0000000000 --- a/lib/active_relation/relations/relation.rb +++ /dev/null @@ -1,111 +0,0 @@ -module ActiveRelation - module Relations - class Base - include SqlBuilder - - module Iteration - include Enumerable - - def each(&block) - connection.select_all(to_s).each(&block) - end - - def first - connection.select_one(to_s) - end - end - include Iteration - - module Operations - def <=>(other) - JoinOperation.new("INNER JOIN", self, other) - end - - def <<(other) - JoinOperation.new("LEFT OUTER JOIN", self, other) - end - - def [](index) - case index - when Symbol - attribute(index) - when ::Range - Range.new(self, index) - end - end - - def include?(attribute) - Predicates::RelationInclusion.new(attribute, self) - end - - def select(*s) - Selection.new(self, *s) - end - - def project(*attributes) - Projection.new(self, *attributes) - end - - def order(*attributes) - Order.new(self, *attributes) - end - - def rename(attribute, aliaz) - Rename.new(self, attribute => aliaz) - end - - def insert(record) - Insertion.new(self, record) - end - - def delete - Deletion.new(self) - end - - class JoinOperation - attr_reader :join_sql, :relation1, :relation2 - - def initialize(join_sql, relation1, relation2) - @join_sql, @relation1, @relation2 = join_sql, relation1, relation2 - end - - def on(*predicates) - Join.new(join_sql, relation1, relation2, *predicates) - end - - def ==(other) - (relation1 == other.relation1 and relation2 == other.relation2) or - (relation1 == other.relation2 and relation2 == other.relation1) - end - end - end - include Operations - - def connection - ActiveRecord::Base.connection - end - - def to_sql(options = {}) - [ - "SELECT #{attributes.collect{ |a| a.to_sql(:use_alias => true) }.join(', ')}", - "FROM #{quote_table_name(table)}", - (joins.to_sql(:quote => false) unless joins.blank?), - ("WHERE #{selects.collect{|s| s.to_sql(:quote => false)}.join("\n\tAND ")}" unless selects.blank?), - ("ORDER BY #{orders.collect(&:to_sql)}" unless orders.blank?), - ("LIMIT #{limit.to_sql}" unless limit.blank?), - ("OFFSET #{offset.to_sql}" unless offset.blank?) - ].compact.join("\n") - end - alias_method :to_s, :to_sql - - protected - def attributes; [] end - def selects; [] end - def orders; [] end - def inserts; [] end - def joins; nil end - def limit; nil end - def offset; nil end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/rename_relation.rb b/lib/active_relation/relations/rename_relation.rb deleted file mode 100644 index 7a1693df57..0000000000 --- a/lib/active_relation/relations/rename_relation.rb +++ /dev/null @@ -1,38 +0,0 @@ -module ActiveRelation - module Relations - class Rename < Compound - attr_reader :relation, :schmattribute, :alias - - def initialize(relation, renames) - @schmattribute, @alias = renames.shift - @relation = renames.empty?? relation : Rename.new(relation, renames) - end - - def ==(other) - relation == other.relation and schmattribute.eql?(other.schmattribute) and self.alias == other.alias - end - - def attributes - relation.attributes.collect { |a| substitute(a) } - end - - def qualify - Rename.new(relation.qualify, schmattribute.qualify => self.alias) - end - - protected - def attribute(name) - case - when name == self.alias then schmattribute.alias(self.alias) - when relation[name].eql?(schmattribute) then nil - else relation[name] - end - end - - private - def substitute(a) - a.eql?(schmattribute) ? a.alias(self.alias) : a - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/selection_relation.rb b/lib/active_relation/relations/selection_relation.rb deleted file mode 100644 index e102d105a0..0000000000 --- a/lib/active_relation/relations/selection_relation.rb +++ /dev/null @@ -1,25 +0,0 @@ -module ActiveRelation - module Relations - class Selection < Compound - attr_reader :relation, :predicate - - def initialize(relation, *predicates) - @predicate = predicates.shift - @relation = predicates.empty?? relation : Selection.new(relation, *predicates) - end - - def ==(other) - relation == other.relation and predicate == other.predicate - end - - def qualify - Selection.new(relation.qualify, predicate.qualify) - end - - protected - def selects - relation.send(:selects) + [predicate] - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/table_relation.rb b/lib/active_relation/relations/table_relation.rb deleted file mode 100644 index 38f540cc52..0000000000 --- a/lib/active_relation/relations/table_relation.rb +++ /dev/null @@ -1,35 +0,0 @@ -module ActiveRelation - module Relations - class Table < Base - attr_reader :table - - def initialize(table) - @table = table - end - - def attributes - attributes_by_name.values - end - - def qualify - Rename.new self, qualifications - end - - protected - def attribute(name) - attributes_by_name[name.to_s] - end - - private - def attributes_by_name - @attributes_by_name ||= connection.columns(table, "#{table} Columns").inject({}) do |attributes_by_name, column| - attributes_by_name.merge(column.name => ActiveRelation::Primitives::Attribute.new(self, column.name.to_sym)) - end - end - - def qualifications - attributes.zip(attributes.collect(&:qualified_name)).to_hash - end - end - end -end
\ No newline at end of file |