aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/dynamic_scope_match.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-12-29 14:38:54 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2008-12-29 14:38:54 -0800
commit276ec16007b03d0a527fb0b83a7ee0b81e460fa1 (patch)
tree224491aa1948d613a551189028746d73400fccce /activerecord/lib/active_record/dynamic_scope_match.rb
parent2e053aec9bafa8735d70886f36dea06ea10dc4ce (diff)
parent490c26c8433a6d278bc61118782da360e8889646 (diff)
downloadrails-276ec16007b03d0a527fb0b83a7ee0b81e460fa1.tar.gz
rails-276ec16007b03d0a527fb0b83a7ee0b81e460fa1.tar.bz2
rails-276ec16007b03d0a527fb0b83a7ee0b81e460fa1.zip
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'activerecord/lib/active_record/dynamic_scope_match.rb')
-rw-r--r--activerecord/lib/active_record/dynamic_scope_match.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/dynamic_scope_match.rb b/activerecord/lib/active_record/dynamic_scope_match.rb
new file mode 100644
index 0000000000..f796ba669a
--- /dev/null
+++ b/activerecord/lib/active_record/dynamic_scope_match.rb
@@ -0,0 +1,25 @@
+module ActiveRecord
+ class DynamicScopeMatch
+ def self.match(method)
+ ds_match = self.new(method)
+ ds_match.scope ? ds_match : nil
+ end
+
+ def initialize(method)
+ @scope = true
+ case method.to_s
+ when /^scoped_by_([_a-zA-Z]\w*)$/
+ names = $1
+ else
+ @scope = nil
+ end
+ @attribute_names = names && names.split('_and_')
+ end
+
+ attr_reader :scope, :attribute_names
+
+ def scope?
+ !@scope.nil?
+ end
+ end
+end