fluke/devops-service/db/mongo/mongo_user.rb
GGA Software Services LLC 02bf8b1bba initial commit
2014-05-08 17:06:06 +04:00

19 lines
431 B
Ruby

require "mongo"
require "db/exceptions/record_not_found"
class MongoUser
def initialize(db, host, port=27017)
@mongo_client = MongoClient.new(host, port)
@db = @mongo_client.db(db)
@users = @db.collection("users")
end
def user username, password
u = @users.find("_id" => username, "password" => password).to_a[0]
raise RecordNotFound.new("User '#{username}' does not exist") if u.nil?
u
end
end