aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-27 17:38:49 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-27 17:38:49 -0700
commit65d74312c86c09ab59af7ff9414db901aa6164f0 (patch)
treeb47c4710bf62f334b1bb627468b5a06db3aaea47 /activerecord
parent133742d185c2abf0fb443b694a305a4b68259bcb (diff)
downloadrails-65d74312c86c09ab59af7ff9414db901aa6164f0.tar.gz
rails-65d74312c86c09ab59af7ff9414db901aa6164f0.tar.bz2
rails-65d74312c86c09ab59af7ff9414db901aa6164f0.zip
constructor should not do so much work; avoid allocating object if possible
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/dynamic_scope_match.rb15
1 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/dynamic_scope_match.rb b/activerecord/lib/active_record/dynamic_scope_match.rb
index 4e51df9e71..c832e927d6 100644
--- a/activerecord/lib/active_record/dynamic_scope_match.rb
+++ b/activerecord/lib/active_record/dynamic_scope_match.rb
@@ -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