Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleaning up mongoid adapter a little

  • Loading branch information...
commit 5c4c179c5aa6e7a483d1416cba1ca9d48c7a22ac 1 parent 78cbea5
Ryan Bates authored
Showing with 7 additions and 18 deletions.
  1. +7 −18 lib/cancan/model_adapters/mongoid_adapter.rb
25 lib/cancan/model_adapters/mongoid_adapter.rb
View
@@ -17,28 +17,17 @@ def self.matches_conditions_hash?(subject, conditions)
def database_records
if @rules.size == 0
- @model_class.where(false_query)
+ @model_class.where(:_id => {'$exists' => false, '$type' => 7}) # return no records in Mongoid
else
- criteria = @model_class.all
- @rules.each do |rule|
- criteria = chain_criteria(rule, criteria)
+ @rules.inject(@model_class.all) do |records, rule|
+ if rule.base_behavior
+ records.or(rule.conditions)
+ else
+ records.excludes(rule.conditions)
+ end
end
- criteria
end
end
-
- def chain_criteria rule, criteria
- if rule.base_behavior
- criteria.or(rule.conditions)
- else
- criteria.excludes(rule.conditions)
- end
- end
-
- def false_query
- # this query is sure to return no results
- {:_id => {'$exists' => false, '$type' => 7}} # type 7 is an ObjectID (default for _id)
- end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.