Permalink
Browse files

Implemented `matches?` method for Scope::Query and Scope::Condition

  • Loading branch information...
1 parent a6198b4 commit 1b0599b1f4158e1b1bb6c67ee3ea7dec8f3199cb @serebryakov serebryakov committed May 28, 2010
Showing with 26 additions and 0 deletions.
  1. +9 −0 lib/lib/scope/condition.rb
  2. +17 −0 lib/lib/scope/query.rb
@@ -35,6 +35,15 @@ def value(required = [])
alias_method :check, :value
##
+ # Checks whether specified object passes all conditions of the query.
+ #
+ # @param [RDFMapper::Model] object
+ ##
+ def matches?(object)
+ object.send(name) == value
+ end
+
+ ##
# [-]
##
def to_triples(subject)
View
@@ -75,6 +75,23 @@ def order
end
##
+ # Checks whether specified object passes all conditions of the query.
+ #
+ # @param [RDFMapper::Model] object
+ ##
+ def matches?(object)
+ unless object.kind_of? RDFMapper::Model
+ return false
+ end
+ unless object.class == @cls
+ return false
+ end
+ to_a.reject do |condition|
+ condition.matches?(object)
+ end.empty?
+ end
+
+ ##
# [-]
##
def [](name)

0 comments on commit 1b0599b

Please sign in to comment.