Sha256: 115ee217b6b0cdd3e9da691e1d6e33b8f29ceb1d162ba35f8a73a009303a54ac
Contents?: true
Size: 612 Bytes
Versions: 3
Compression:
Stored size: 612 Bytes
Contents
module Mongoid module Ids 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) 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 end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mongoid-ids-0.1.8 | lib/mongoid/ids/finders.rb |
mongoid-ids-0.1.7 | lib/mongoid/ids/finders.rb |
mongoid-ids-0.1.1 | lib/mongoid/ids/finders.rb |