diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-27 16:20:32 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-27 16:20:46 -0700 |
commit | b1f5e90839a760c926403046ef43dd60af9fcf07 (patch) | |
tree | c14d526ed063b9c55df3d39dc3009a7dec2adda3 /activerecord/lib/active_record/dynamic_scope_match.rb | |
parent | f6ef4d383edd0403e5c2bb8390c9fec9f0843722 (diff) | |
download | rails-b1f5e90839a760c926403046ef43dd60af9fcf07.tar.gz rails-b1f5e90839a760c926403046ef43dd60af9fcf07.tar.bz2 rails-b1f5e90839a760c926403046ef43dd60af9fcf07.zip |
no need for a case / when statement
Diffstat (limited to 'activerecord/lib/active_record/dynamic_scope_match.rb')
-rw-r--r-- | activerecord/lib/active_record/dynamic_scope_match.rb | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/dynamic_scope_match.rb b/activerecord/lib/active_record/dynamic_scope_match.rb index 61c3ea0e7f..4e51df9e71 100644 --- a/activerecord/lib/active_record/dynamic_scope_match.rb +++ b/activerecord/lib/active_record/dynamic_scope_match.rb @@ -8,25 +8,21 @@ module ActiveRecord # scope except that it's dynamic. class DynamicScopeMatch def self.match(method) - ds_match = self.new(method) - ds_match.scope ? ds_match : nil + ds_match = new(method) + ds_match.scope && ds_match end def initialize(method) - @scope = true - case method.to_s - when /^scoped_by_([_a-zA-Z]\w*)$/ + @scope = nil + if method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/ names = $1 - else - @scope = nil + @scope = true end + @attribute_names = names && names.split('_and_') end attr_reader :scope, :attribute_names - - def scope? - !@scope.nil? - end + alias :scope? :scope end end |