Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / activerecord / lib / active_record / dynamic_scope_match.rb
diff --git a/vendor/rails/activerecord/lib/active_record/dynamic_scope_match.rb b/vendor/rails/activerecord/lib/active_record/dynamic_scope_match.rb
new file mode 100644 (file)
index 0000000..f796ba6
--- /dev/null
@@ -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