mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Use explicit method definition instead of metaprogramming.
This commit is contained in:
@@ -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 @@ module ActiveRecord
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user