Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

the necessities

  • Loading branch information...
commit 9d7f7fed2375a7a49cf59ab4d54898cdd4a5a7a2 0 parents
Dan Croak authored
2  .gitignore
... ... @@ -0,0 +1,2 @@
  1 +*.swp
  2 +pkg
21 LICENSE
... ... @@ -0,0 +1,21 @@
  1 +The MIT License
  2 +
  3 +Copyright (c) 2010 Dan Croak
  4 +
  5 +Permission is hereby granted, free of charge, to any person obtaining a copy
  6 +of this software and associated documentation files (the "Software"), to deal
  7 +in the Software without restriction, including without limitation the rights
  8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9 +copies of the Software, and to permit persons to whom the Software is
  10 +furnished to do so, subject to the following conditions:
  11 +
  12 +The above copyright notice and this permission notice shall be included in
  13 +all copies or substantial portions of the Software.
  14 +
  15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21 +THE SOFTWARE.
46 README.md
Source Rendered
... ... @@ -0,0 +1,46 @@
  1 +Sinatra Mongoid
  2 +===============
  3 +
  4 +A Mongoid extension for Sinatra.
  5 +
  6 +Usage
  7 +-----
  8 +
  9 +Install the gem:
  10 +
  11 + sudo gem install sinatra-mongoid
  12 +
  13 +Create your Sinatra app:
  14 +
  15 + require 'rubygems'
  16 + require 'sinatra'
  17 + require 'sinatra/mongoid'
  18 +
  19 + set :mongo_db, 'job-board'
  20 +
  21 + configure :production do
  22 + set :mongo_host, 'db.mongohq.com'
  23 + end
  24 +
  25 +Configuration
  26 +-------------
  27 +
  28 +All Sinatra options you can set are:
  29 +
  30 + :mongo_host
  31 + :mongo_db
  32 + :mongo_user
  33 + :mongo_password
  34 +
  35 +Their default values are:
  36 +
  37 + ENV['MONGO_HOST'] || 'localhost'
  38 + ENV['MONGO_DB']
  39 + ENV['MONGO_USER']
  40 + ENV['MONGO_PASSWORD']
  41 +
  42 +Resources
  43 +---------
  44 +
  45 +* [Mongoid](http://mongoid.org)
  46 +* [Sinatra](http://sinatrarb.com)
15 Rakefile
... ... @@ -0,0 +1,15 @@
  1 +require 'jeweler'
  2 +
  3 +Jeweler::Tasks.new do |gem|
  4 + gem.name = "sinatra-mongoid"
  5 + gem.summary = "A Mongoid extension for Sinatra."
  6 + gem.description = "Like a blind date for the nastiest Ruby Mongo ORM and web framework."
  7 + gem.email = "dcroak@thoughtbot.com"
  8 + gem.homepage = "http://github.com/dancroak/sinatra-mongoid"
  9 + gem.authors = ["Dan Croak"]
  10 +
  11 + gem.add_dependency("sinatra")
  12 + gem.add_dependency("mongoid")
  13 +end
  14 +
  15 +Jeweler::GemcutterTasks.new
26 lib/sinatra/mongoid.rb
... ... @@ -0,0 +1,26 @@
  1 +require 'sinatra/base'
  2 +require 'mongoid'
  3 +require 'mongo_ext'
  4 +
  5 +module Sinatra
  6 + module MongoidExtension
  7 + module DatabaseConnection
  8 + connection = Mongo::Connection.new(mongo_host)
  9 + Mongoid.database = connection.db(mongo_db)
  10 + if mongo_user
  11 + Mongoid.database.authenticate(mongo_user, mongo_password)
  12 + end
  13 + end
  14 +
  15 + def self.registered(app)
  16 + app.set :mongo_host, ENV['MONGO_HOST'] || 'localhost'
  17 + app.set :mongo_db, ENV['MONGO_DB']
  18 + app.set :mongo_user, ENV['MONGO_USER']
  19 + app.set :mongo_password, ENV['MONGO_PASSWORD']
  20 +
  21 + app.helpers MongoidExtension::DatabaseConnection
  22 + end
  23 + end
  24 +
  25 + register MongoidExtension
  26 +end

0 comments on commit 9d7f7fe

Please sign in to comment.
Something went wrong with that request. Please try again.