提交 65d74312 编写于 作者: A Aaron Patterson

constructor should not do so much work; avoid allocating object if possible

上级 133742d1
......@@ -8,18 +8,13 @@ module ActiveRecord
# scope except that it's dynamic.
class DynamicScopeMatch
def self.match(method)
ds_match = new(method)
ds_match.scope && ds_match
return unless method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
new(true, $1 && $1.split('_and_'))
end
def initialize(method)
@scope = nil
if method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
names = $1
@scope = true
end
@attribute_names = names && names.split('_and_')
def initialize(scope, attribute_names)
@scope = scope
@attribute_names = attribute_names
end
attr_reader :scope, :attribute_names
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册