aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_relation/primitives
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2008-01-14 10:50:46 -0500
committerBryan Helmkamp <bryan@brynary.com>2008-01-14 10:50:46 -0500
commit553eb0ad490abc7f85d9836c3ba959ab771d3cf4 (patch)
treebaa9714465488d77980e8d252a82849b32844d3b /lib/active_relation/primitives
parent17a5fd13bc4ba8405d95e90d12b87dcd7e5bea5b (diff)
downloadrails-553eb0ad490abc7f85d9836c3ba959ab771d3cf4.tar.gz
rails-553eb0ad490abc7f85d9836c3ba959ab771d3cf4.tar.bz2
rails-553eb0ad490abc7f85d9836c3ba959ab771d3cf4.zip
Remove ActiveRelation sub-modules and refactor specs
Diffstat (limited to 'lib/active_relation/primitives')
-rw-r--r--lib/active_relation/primitives/aggregation.rb28
-rw-r--r--lib/active_relation/primitives/attribute.rb134
2 files changed, 78 insertions, 84 deletions
diff --git a/lib/active_relation/primitives/aggregation.rb b/lib/active_relation/primitives/aggregation.rb
index 189eb33ac9..48f8946835 100644
--- a/lib/active_relation/primitives/aggregation.rb
+++ b/lib/active_relation/primitives/aggregation.rb
@@ -1,19 +1,17 @@
module ActiveRelation
- module Primitives
- class Aggregation
- attr_reader :attribute, :function_sql
-
- def initialize(attribute, function_sql)
- @attribute, @function_sql = attribute, function_sql
- end
-
- def to_sql(strategy = nil)
- "#{function_sql}(#{attribute.to_sql})"
- end
-
- def ==(other)
- self.class == other.class and attribute == other.attribute and function_sql == other.function_sql
- end
+ class Aggregation
+ attr_reader :attribute, :function_sql
+
+ def initialize(attribute, function_sql)
+ @attribute, @function_sql = attribute, function_sql
+ end
+
+ def to_sql(strategy = nil)
+ "#{function_sql}(#{attribute.to_sql})"
+ end
+
+ def ==(other)
+ self.class == other.class and attribute == other.attribute and function_sql == other.function_sql
end
end
end \ No newline at end of file
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb
index 6ebaf1b292..90bbe8012b 100644
--- a/lib/active_relation/primitives/attribute.rb
+++ b/lib/active_relation/primitives/attribute.rb
@@ -1,83 +1,79 @@
module ActiveRelation
- module Primitives
- class Attribute
- attr_reader :relation, :name, :alias
-
- def initialize(relation, name, aliaz = nil)
- @relation, @name, @alias = relation, name, aliaz
+ class Attribute
+ attr_reader :relation, :name, :alias
+
+ def initialize(relation, name, aliaz = nil)
+ @relation, @name, @alias = relation, name, aliaz
+ end
+
+ def as(aliaz = nil)
+ Attribute.new(relation, name, aliaz)
+ end
+
+ def qualified_name
+ "#{relation.name}.#{name}"
+ end
+
+ def qualify
+ self.as(qualified_name)
+ end
+
+ def ==(other)
+ relation == other.relation and name == other.name and @alias == other.alias
+ end
+
+ module Predications
+ def equals(other)
+ Equality.new(self, other)
end
-
- def as(aliaz = nil)
- Attribute.new(relation, name, aliaz)
+
+ def less_than(other)
+ LessThan.new(self, other)
end
-
- def qualified_name
- "#{relation.name}.#{name}"
+
+ def less_than_or_equal_to(other)
+ LessThanOrEqualTo.new(self, other)
end
-
- def qualify
- self.as(qualified_name)
+
+ def greater_than(other)
+ GreaterThan.new(self, other)
end
-
- def ==(other)
- relation == other.relation and name == other.name and @alias == other.alias
+
+ def greater_than_or_equal_to(other)
+ GreaterThanOrEqualTo.new(self, other)
end
- module Predications
- include Predicates
-
- def equals(other)
- Equality.new(self, other)
- end
-
- def less_than(other)
- LessThan.new(self, other)
- end
-
- def less_than_or_equal_to(other)
- LessThanOrEqualTo.new(self, other)
- end
-
- def greater_than(other)
- GreaterThan.new(self, other)
- end
-
- def greater_than_or_equal_to(other)
- GreaterThanOrEqualTo.new(self, other)
- end
-
- def matches(regexp)
- Match.new(self, regexp)
- end
+ def matches(regexp)
+ Match.new(self, regexp)
+ end
+ end
+ include Predications
+
+ module Aggregations
+ def count
+ Aggregation.new(self, "COUNT")
+ end
+
+ def sum
+ Aggregation.new(self, "SUM")
+ end
+
+ def maximum
+ Aggregation.new(self, "MAX")
end
- include Predications
- module Aggregations
- def count
- Aggregation.new(self, "COUNT")
- end
-
- def sum
- Aggregation.new(self, "SUM")
- end
-
- def maximum
- Aggregation.new(self, "MAX")
- end
-
- def minimum
- Aggregation.new(self, "MIN")
- end
-
- def average
- Aggregation.new(self, "AVG")
- end
+ def minimum
+ Aggregation.new(self, "MIN")
end
- include Aggregations
-
- def to_sql(strategy = Sql::Predicate.new)
- strategy.attribute relation.name, name, self.alias
+
+ def average
+ Aggregation.new(self, "AVG")
end
end
+ include Aggregations
+
+ def to_sql(strategy = Sql::Predicate.new)
+ strategy.attribute relation.name, name, self.alias
+ end
end
end \ No newline at end of file