Skip to content

Commit

Permalink
splitting main.rb into main.rb and init.rb for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
gnugeek committed Dec 25, 2008
1 parent 3064e28 commit ec52f44
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
41 changes: 41 additions & 0 deletions init.rb
@@ -0,0 +1,41 @@
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-validations'
require 'sass'
require 'logger'
require 'yaml'
require 'helpers'

Dir.glob(File.join(File.dirname(__FILE__), 'models/*.rb')).each {|f| require f }
DBCONFIG = YAML.load_file('database.yml') unless defined?(DBCONFIG)

configure :test do
DataMapper.setup(:default, {
:host => DBCONFIG['test']['host'],
:adapter => DBCONFIG['test']['adapter'],
:database => DBCONFIG['test']['database'],
:username => DBCONFIG['test']['username'],
:password => DBCONFIG['test']['password']
})
end

configure :development do
DataMapper.setup(:default, {
:host => DBCONFIG['development']['host'],
:adapter => DBCONFIG['development']['adapter'],
:database => DBCONFIG['development']['database'],
:username => DBCONFIG['development']['username'],
:password => DBCONFIG['development']['password']
})
end

configure :production do
DataMapper.setup(:default, {
:host => DBCONFIG['production']['host'],
:adapter => DBCONFIG['production']['adapter'],
:database => DBCONFIG['production']['database'],
:username => DBCONFIG['production']['username'],
:password => DBCONFIG['production']['password']
})
end
42 changes: 1 addition & 41 deletions main.rb
@@ -1,44 +1,4 @@
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-validations'
require 'sass'
require 'logger'
require 'yaml'
require 'helpers'

Dir.glob(File.join(File.dirname(__FILE__), 'models/*.rb')).each {|f| require f }
DBCONFIG = YAML.load_file('database.yml') unless defined?(DBCONFIG)

configure :test do
DataMapper.setup(:default, {
:host => DBCONFIG['test']['host'],
:adapter => DBCONFIG['test']['adapter'],
:database => DBCONFIG['test']['database'],
:username => DBCONFIG['test']['username'],
:password => DBCONFIG['test']['password']
})
end

configure :development do
DataMapper.setup(:default, {
:host => DBCONFIG['development']['host'],
:adapter => DBCONFIG['development']['adapter'],
:database => DBCONFIG['development']['database'],
:username => DBCONFIG['development']['username'],
:password => DBCONFIG['development']['password']
})
end

configure :production do
DataMapper.setup(:default, {
:host => DBCONFIG['production']['host'],
:adapter => DBCONFIG['production']['adapter'],
:database => DBCONFIG['production']['database'],
:username => DBCONFIG['production']['username'],
:password => DBCONFIG['production']['password']
})
end
require 'init.rb'

get '/' do
haml :index
Expand Down

0 comments on commit ec52f44

Please sign in to comment.