Skip to content

Commit

Permalink
Ditched YAML -- die, you dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Nelson and Chris Wilson authored and begriffs committed Jun 29, 2012
1 parent ecc7974 commit 6607b50
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db/config.yml
db/config.rb
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source 'http://rubygems.org'
gem 'sinatra'
gem 'pg'
gem 'psych'
6 changes: 0 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -19,7 +15,5 @@ PLATFORMS
ruby

DEPENDENCIES
fileutils
pg
psych
sinatra
22 changes: 12 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'sinatra'
require 'pg'
require 'psych'

require './init'

get '/' do
Expand Down
11 changes: 11 additions & 0 deletions db/config.rb.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use any options accepted by PG::Connection#new.
module DB
Config = {
development: {
host: 'localhost',
dbname: 'trails-development'
},
test: {},
production: {}
}
end
16 changes: 0 additions & 16 deletions db/config.yml.example

This file was deleted.

5 changes: 2 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6607b50

Please sign in to comment.