Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit e8948e6ed2c1887e2ff8f753c9762d5605043cc0 0 parents
@sdsantos authored
Showing with 84 additions and 0 deletions.
  1. +5 −0 Gemfile
  2. +36 −0 Gemfile.lock
  3. +7 −0 README.textile
  4. +34 −0 app.rb
  5. +2 −0  config.ru
5 Gemfile
@@ -0,0 +1,5 @@
+source :rubygems
+gem 'sinatra'
+gem 'mongoid'
+gem 'bson_ext', "1.1.1"
+gem 'activesupport'
36 Gemfile.lock
@@ -0,0 +1,36 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activesupport (3.0.0)
+ bson (1.1.1)
+ bson_ext (1.1.1)
+ builder (2.1.2)
+ i18n (0.4.2)
+ mongo (1.1.1)
+ bson (>= 1.1.1)
+ mongoid (2.0.0.beta.20)
+ activemodel (~> 3.0)
+ mongo (~> 1.1)
+ tzinfo (~> 0.3.22)
+ will_paginate (~> 3.0.pre)
+ rack (1.2.1)
+ sinatra (1.1.0)
+ rack (~> 1.1)
+ tilt (~> 1.1)
+ tilt (1.1)
+ tzinfo (0.3.23)
+ will_paginate (3.0.pre2)
+
+PLATFORMS
+ ruby
+ x86-mingw32
+
+DEPENDENCIES
+ activesupport
+ bson_ext (= 1.1.1)
+ mongoid
+ sinatra
7 README.textile
@@ -0,0 +1,7 @@
+h1. Sinatra Mongoid App
+
+A template "Sinatra":http://www.sinatrarb.com application configured for using a MongoDB database through "Mongoid":http://mongoid.org.
+
+It works out of the box with Heroku and the "MongoHQ add-on":http://addons.heroku.com/mongohq.
+
+by "S�rgio Santos":http://sergiosantos.info
34 app.rb
@@ -0,0 +1,34 @@
+require 'rubygems'
+require 'sinatra'
+require 'mongoid'
+
+# MongoDB configuration
+Mongoid.configure do |config|
+ if ENV['MONGOHQ_URL']
+ conn = Mongo::Connection.from_uri(ENV['MONGOHQ_URL'])
+ uri = URI.parse(ENV['MONGOHQ_URL'])
+ config.master = conn.db(uri.path.gsub(/^\//, ''))
+ else
+ config.master = Mongo::Connection.from_uri("mongodb://localhost:27017").db('test')
+ end
+end
+
+# Models
+class Counter
+ include Mongoid::Document
+
+ field :count, :type => Integer
+
+ def self.increment
+ c = first || new({:count => 0})
+ c.inc(:count, 1)
+ c.save
+ c.count
+ end
+end
+
+# Controllers
+get '/' do
+ "Hello visitor nº" + Counter.increment.to_s
+end
+
2  config.ru
@@ -0,0 +1,2 @@
+require 'app'
+run Sinatra::Application
Please sign in to comment.
Something went wrong with that request. Please try again.