Sha256: 95ed43783c9ca6496a54d3c954ba31145e05d6e59e06f956b8c83491bbb7b11f
Contents?: true
Size: 1.16 KB
Versions: 10
Compression:
Stored size: 1.16 KB
Contents
require 'mongoid' Mongoid.configure do |config| config.master = Mongo::Connection.new.db('testing') end Mongoid.database.collections.each do |coll| coll.remove end class User include Mongoid::Document field :username, :type => String field :email, :type => String def self.find_record(login) found = where(:username => login).to_a found = where(:email => login).to_a if found.empty? found end def self.find_record_generic(attributes) where(attributes).first end def self.find_record_alt(login) where("function() {return this.username == '#{login}' || this.email == '#{login}'}") end end User.create :username => 'guest', :email => 'guest@email.com' User.create :username => 'admin', :email => 'admin@email.com' User.create :username => 'blip', :email => 'guest@email.com' User.create :username => 'blip', :email => 'guest@cool.com' puts User.all puts "Found match 'blip'" # puts User.find_record('blip').first.inspect puts User.find_record_alt('blip').first.inspect # puts User.find_record_generic(:username => 'blip') puts "Found match 'guest@email.com'" puts User.find_record('guest@email.com').first.inspect
Version data entries
10 entries across 10 versions & 3 rubygems