Skip to content
Browse files

Ditched YAML -- die, you dsl

  • Loading branch information...
1 parent ecc7974 commit 6607b50edd4b4e2f96f7f95e9914ad5c817588db Joe Nelson and Chris Wilson committed with Jun 29, 2012
Showing with 26 additions and 39 deletions.
  1. +1 −1 .gitignore
  2. +0 −1 Gemfile
  3. +0 −6 Gemfile.lock
  4. +12 −10 Rakefile
  5. +0 −2 app.rb
  6. +11 −0 db/config.rb.example
  7. +0 −16 db/config.yml.example
  8. +2 −3 init.rb
View
2 .gitignore
@@ -1 +1 @@
-db/config.yml
+db/config.rb
View
1 Gemfile
@@ -1,4 +1,3 @@
source 'http://rubygems.org'
gem 'sinatra'
gem 'pg'
-gem 'psych'
View
6 Gemfile.lock
@@ -1,14 +1,10 @@
GEM
remote: http://rubygems.org/
specs:
- fileutils (0.7)
- rmagick (>= 2.13.1)
pg (0.14.0)
- psych (1.3.3)
rack (1.4.1)
rack-protection (1.2.0)
rack
- rmagick (2.13.1)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
@@ -19,7 +15,5 @@ PLATFORMS
ruby
DEPENDENCIES
- fileutils
pg
- psych
sinatra
View
22 Rakefile
@@ -1,20 +1,22 @@
require 'rake'
require 'pg'
-require 'psych'
-
-$config = Psych.load File.open("db/config.yml", "r").read
-$config.select! { |name, env| env.has_key? 'dbname' }
+require './db/config.rb'
task 'db:create' do
- $config.each do |env, opts|
- sh "createdb #{opts['dbname']}"
- sql "create table schema_info(version integer not null)", env
- sql "insert into schema_info (version) values (0)", env
+ DB::Config.each do |env, opts|
+ if opts[:dbname]
+ sh "createdb #{opts[:dbname]}"
+ sql env, <<-eoq
+ create table schema_info
+ (version integer not null check (version >= 0))
+ eoq
+ sql env, "insert into schema_info (version) values (0)"
+ end
end
end
task 'db:drop' do
- $config.each_value { |opts| sh "dropdb #{opts['dbname']}" }
+ DB::Config.each_value { |opts| sh "dropdb #{opts[:dbname]}" if opts[:dbname] }
end
task :migration do
@@ -65,7 +67,7 @@ end
def sql s, env='development', args=[]
$db ||= Hash.new
- $db[env] ||= PG::Connection.new $config[env]
+ $db[env] ||= PG::Connection.new DB::Config[env]
$db[env].exec s, args
end
View
2 app.rb
@@ -1,7 +1,5 @@
require 'sinatra'
require 'pg'
-require 'psych'
-
require './init'
get '/' do
View
11 db/config.rb.example
@@ -0,0 +1,11 @@
+# Use any options accepted by PG::Connection#new.
+module DB
+ Config = {
+ development: {
+ host: 'localhost',
+ dbname: 'trails-development'
+ },
+ test: {},
+ production: {}
+ }
+end
View
16 db/config.yml.example
@@ -1,16 +0,0 @@
-# Use any options accepted by PG::Connection#new.
-# Leave dbname blank to ignore an environment.
-common: &COMMON
- host: localhost
-
-development:
- <<: *COMMON
- dbname:
-
-test:
- <<: *COMMON
- dbname:
-
-production:
- <<: *COMMON
- dbname:
View
5 init.rb
@@ -1,7 +1,6 @@
configure do
- conf = Psych.load File.open("db/config.yml", "r").read
- env = settings.environment.to_s
- $db = PG::Connection.new conf[env] if conf[env].has_key? 'dbname'
+ opts = DB::Config[settings.environment.to_s]
+ $db = PG::Connection.new opts if opts.has_key? 'dbname'
end
def sql cmd, *args

0 comments on commit 6607b50

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