Permalink
Browse files

Use explicit method definition instead of metaprogramming.

  • Loading branch information...
1 parent fa8f5c2 commit ac03bc91dbee36233e061eb624f7781a49ab6fcf @miloops miloops committed Aug 18, 2009
Showing with 16 additions and 11 deletions.
  1. +16 −11 activerecord/lib/active_record/relation.rb
@@ -1,7 +1,6 @@
module ActiveRecord
class Relation
- delegate :delete, :to_sql, :to => :relation
- CLAUSES_METHODS = ["group", "order", "on"].freeze
+ delegate :to_sql, :to => :relation
attr_reader :relation, :klass
def initialize(klass, table = nil)
@@ -22,20 +21,26 @@ def first
to_a.first
end
- for clause in CLAUSES_METHODS
- class_eval %{
- def #{clause}!(_#{clause})
- @relation = @relation.#{clause}(_#{clause}) if _#{clause}
- self
- end
- }
- end
-
def select!(selection)
@relation = @relation.project(selection) if selection
self
end
+ def on!(on)
+ @relation = @relation.on(on) if on
+ self
+ end
+
+ def order!(order)
+ @relation = @relation.order(order) if order
+ self
+ end
+
+ def group!(group)
+ @relation = @relation.group(group) if group
+ self
+ end
+
def limit!(limit)
@relation = @relation.take(limit) if limit
self

0 comments on commit ac03bc9

Please sign in to comment.