Browse files

ActiveRecord support for postgres

  • Loading branch information...
1 parent 2706e29 commit 43e61b644320dead31490e44d9f393bd52d49bc7 @6 committed Dec 1, 2012
Showing with 49 additions and 3 deletions.
  1. +3 −0 Gemfile
  2. +22 −0 Gemfile.lock
  3. +2 −0 Rakefile
  4. +1 −1 console
  5. 0 db/migrate/.gitkeep
  6. +21 −2 server/application.rb
  7. 0 server/models/.gitkeep
View
3 Gemfile
@@ -1,13 +1,16 @@
source :rubygems
+gem 'activerecord'
gem 'bootstrap-sass'
gem 'coffee-script'
gem 'compass'
gem 'haml'
gem 'less'
gem 'newrelic_rpm'
+gem 'pg'
gem 'sass'
gem 'sinatra'
+gem 'sinatra-activerecord'
gem 'sinatra-contrib'
gem 'sprockets'
gem 'sprockets-sass'
View
22 Gemfile.lock
@@ -5,9 +5,22 @@ GEM
Platform (>= 0.4.0)
open4
Platform (0.4.0)
+ activemodel (3.2.9)
+ activesupport (= 3.2.9)
+ builder (~> 3.0.0)
+ activerecord (3.2.9)
+ activemodel (= 3.2.9)
+ activesupport (= 3.2.9)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activesupport (3.2.9)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
addressable (2.2.8)
+ arel (3.0.2)
backports (2.5.1)
bootstrap-sass (2.0.2)
+ builder (3.0.4)
childprocess (0.3.3)
ffi (~> 1.0.6)
chunky_png (1.2.5)
@@ -38,6 +51,7 @@ GEM
sprockets (>= 2.0.3)
tilt (>= 1.3.3)
hike (1.2.1)
+ i18n (0.6.1)
jasmine (1.2.0)
jasmine-core (>= 1.2.0)
rack (~> 1.0)
@@ -57,6 +71,7 @@ GEM
multi_json (1.3.4)
newrelic_rpm (3.4.0.1)
open4 (1.3.0)
+ pg (0.14.1)
rack (1.4.1)
rack-protection (1.2.0)
rack
@@ -90,6 +105,9 @@ GEM
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
+ sinatra-activerecord (1.1.2)
+ activerecord (~> 3.0)
+ sinatra (~> 1.0)
sinatra-contrib (1.3.1)
backports (>= 2.0)
eventmachine
@@ -109,6 +127,7 @@ GEM
libv8 (~> 3.3.10)
thor (0.15.0)
tilt (1.3.3)
+ tzinfo (0.3.35)
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
@@ -123,6 +142,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ activerecord
bootstrap-sass
coffee-script
colored
@@ -135,10 +155,12 @@ DEPENDENCIES
jasmine
less
newrelic_rpm
+ pg
rake
rerun
sass
sinatra
+ sinatra-activerecord
sinatra-contrib
sprockets
sprockets-sass
View
2 Rakefile
@@ -1,3 +1,5 @@
+require './server/application.rb'
+require 'sinatra/activerecord/rake'
require 'colored'
require 'guard'
require 'jasmine'
View
2 console
@@ -1,2 +1,2 @@
#!/usr/bin/env sh
-RACK_ENV=development irb -r ./server/application.rb
+irb -r ./server/application.rb
View
0 db/migrate/.gitkeep
No changes.
View
23 server/application.rb
@@ -1,15 +1,34 @@
require 'sinatra'
require 'sinatra/contrib'
+require 'sinatra/activerecord'
require 'json'
-%w[lib server].each do |dir|
+ENV['RACK_ENV'] ||= 'development'
+ENV['DATABASE_URL'] ||= "postgres://postgres@localhost/sinatra_backbone_#{ENV['RACK_ENV']}"
+
+db = URI.parse(ENV['DATABASE_URL'])
+
+DB_SETTINGS = {
+ :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
+ :host => db.host,
+ :username => db.user,
+ :password => db.password,
+ :database => db.path[1..-1],
+ :encoding => 'utf8',
+ :pool => 10,
+ :port => db.port,
+}
+
+ActiveRecord::Base.establish_connection(DB_SETTINGS)
+
+%w[lib server server/models].each do |dir|
Dir.glob("./#{dir}/*.rb").each do |relative_path|
p relative_path
require relative_path unless relative_path == "./server/application.rb"
end
end
-set :sprockets, SprocketsEnvironmentBuilder.build(ENV['RACK_ENV'] || 'development')
+set :sprockets, SprocketsEnvironmentBuilder.build(ENV['RACK_ENV'])
configure :production do
require 'newrelic_rpm'
View
0 server/models/.gitkeep
No changes.

0 comments on commit 43e61b6

Please sign in to comment.