mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use explicit method definition instead of metaprogramming.
This commit is contained in:
parent
fa8f5c2667
commit
ac03bc91db
1 changed files with 16 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
class Relation
|
class Relation
|
||||||
delegate :delete, :to_sql, :to => :relation
|
delegate :to_sql, :to => :relation
|
||||||
CLAUSES_METHODS = ["group", "order", "on"].freeze
|
|
||||||
attr_reader :relation, :klass
|
attr_reader :relation, :klass
|
||||||
|
|
||||||
def initialize(klass, table = nil)
|
def initialize(klass, table = nil)
|
||||||
|
@ -22,20 +21,26 @@ module ActiveRecord
|
||||||
to_a.first
|
to_a.first
|
||||||
end
|
end
|
||||||
|
|
||||||
for clause in CLAUSES_METHODS
|
|
||||||
class_eval %{
|
|
||||||
def #{clause}!(_#{clause})
|
|
||||||
@relation = @relation.#{clause}(_#{clause}) if _#{clause}
|
|
||||||
self
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def select!(selection)
|
def select!(selection)
|
||||||
@relation = @relation.project(selection) if selection
|
@relation = @relation.project(selection) if selection
|
||||||
self
|
self
|
||||||
end
|
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)
|
def limit!(limit)
|
||||||
@relation = @relation.take(limit) if limit
|
@relation = @relation.take(limit) if limit
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in a new issue