constructor should not do so much work; avoid allocating object if possible
This commit is contained in:
parent
133742d185
commit
65d74312c8
@ -8,18 +8,13 @@ module ActiveRecord
|
|||||||
# scope except that it's dynamic.
|
# scope except that it's dynamic.
|
||||||
class DynamicScopeMatch
|
class DynamicScopeMatch
|
||||||
def self.match(method)
|
def self.match(method)
|
||||||
ds_match = new(method)
|
return unless method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
|
||||||
ds_match.scope && ds_match
|
new(true, $1 && $1.split('_and_'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(method)
|
def initialize(scope, attribute_names)
|
||||||
@scope = nil
|
@scope = scope
|
||||||
if method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
|
@attribute_names = attribute_names
|
||||||
names = $1
|
|
||||||
@scope = true
|
|
||||||
end
|
|
||||||
|
|
||||||
@attribute_names = names && names.split('_and_')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :scope, :attribute_names
|
attr_reader :scope, :attribute_names
|
||||||
|
Loading…
Reference in New Issue
Block a user