no need for a case / when statement
This commit is contained in:
parent
f6ef4d383e
commit
b1f5e90839
@ -8,25 +8,21 @@ 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 = self.new(method)
|
ds_match = new(method)
|
||||||
ds_match.scope ? ds_match : nil
|
ds_match.scope && ds_match
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(method)
|
def initialize(method)
|
||||||
@scope = true
|
@scope = nil
|
||||||
case method.to_s
|
if method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
|
||||||
when /^scoped_by_([_a-zA-Z]\w*)$/
|
|
||||||
names = $1
|
names = $1
|
||||||
else
|
@scope = true
|
||||||
@scope = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@attribute_names = names && names.split('_and_')
|
@attribute_names = names && names.split('_and_')
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :scope, :attribute_names
|
attr_reader :scope, :attribute_names
|
||||||
|
alias :scope? :scope
|
||||||
def scope?
|
|
||||||
!@scope.nil?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user