aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-27 18:07:35 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-27 18:07:35 -0700
commit7752b2fa629d55e870342b1bafa57d6805007497 (patch)
tree11ac9011c1802bffbe4479a69737778388d0a75c /activerecord
parent526ade1ff63ba1fcb32250841b29c95ae4cb9de9 (diff)
downloadrails-7752b2fa629d55e870342b1bafa57d6805007497.tar.gz
rails-7752b2fa629d55e870342b1bafa57d6805007497.tar.bz2
rails-7752b2fa629d55e870342b1bafa57d6805007497.zip
be kind to the garbage collector: only instantiate objects when absolutely necessary
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/dynamic_finder_match.rb31
1 files changed, 17 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/dynamic_finder_match.rb b/activerecord/lib/active_record/dynamic_finder_match.rb
index 9493272483..b309df9b1b 100644
--- a/activerecord/lib/active_record/dynamic_finder_match.rb
+++ b/activerecord/lib/active_record/dynamic_finder_match.rb
@@ -6,30 +6,33 @@ module ActiveRecord
#
class DynamicFinderMatch
def self.match(method)
- df_match = new(method)
- df_match.finder && df_match
- end
-
- def initialize(method)
- @finder = :first
- @bang = false
- @instantiator = nil
+ finder = :first
+ bang = false
+ instantiator = nil
case method.to_s
when /^find_(all_|last_)?by_([_a-zA-Z]\w*)$/
- @finder = :last if $1 == 'last_'
- @finder = :all if $1 == 'all_'
+ finder = :last if $1 == 'last_'
+ finder = :all if $1 == 'all_'
names = $2
when /^find_by_([_a-zA-Z]\w*)\!$/
- @bang = true
+ bang = true
names = $1
when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
- @instantiator = $1 == 'initialize' ? :new : :create
+ instantiator = $1 == 'initialize' ? :new : :create
names = $2
else
- @finder = nil
+ return nil
end
- @attribute_names = names && names.split('_and_')
+
+ new(finder, instantiator, bang, names.split('_and_'))
+ end
+
+ def initialize(finder, instantiator, bang, attribute_names)
+ @finder = finder
+ @instantiator = instantiator
+ @bang = bang
+ @attribute_names = attribute_names
end
attr_reader :finder, :attribute_names, :instantiator