lib/mongoid/token/finders.rb in mongoid_token-2.1.1 vs lib/mongoid/token/finders.rb in mongoid_token-2.1.2
- old
+ new
@@ -1,10 +1,14 @@
module Mongoid
module Token
module Finders
def self.define_custom_token_finder_for(klass, field_name = :token)
- klass.define_singleton_method(:"find_by_#{field_name.to_s}") do |token|
- self.find_by(field_name.to_sym => token)
+ klass.define_singleton_method(:"find_by_#{field_name}") do |token|
+ if token.is_a?(Array)
+ self.in field_name.to_sym => token
+ else
+ self.find_by field_name.to_sym => token
+ end
end
klass.define_singleton_method :"find_with_#{field_name}" do |*args| # this is going to be painful if tokens happen to look like legal object ids
args.all?{|arg| BSON::ObjectId.legal?(arg)} ? send(:"find_without_#{field_name}",*args) : klass.send(:"find_by_#{field_name.to_s}", args.first)
end