forked from codeunion/examples-sinatra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.rb
45 lines (37 loc) · 1.32 KB
/
setup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require "sinatra"
# The code below will automatically require all the gems listed in our Gemfile,
# so we don't have to manually require gems a la
#
# require 'data_mapper'
# require 'dotenv'
#
# See: http://bundler.io/sinatra.html
require "rubygems"
require "bundler/setup"
# Bundler.require(...) requires all gems necessary regardless of
# environment (:default) in addition to all environment-specific gems.
Bundler.require(:default, Sinatra::Application.environment)
# NOTE:
# Sinatra::Application.environment is set to the value of ENV['RACK_ENV']
# if RACK_ENV is set. Otherwise, it defaults to :development.
# Load the .env file if it exists
if File.exist?(".env")
Dotenv.load(".env")
end
# Yell at the user (and exit) if DATABASE_URL isn't set
unless ENV.key?("DATABASE_URL")
puts "ENV['DATABASE_URL'] is undefined. Make sure your .env file is correct."
puts "To use the example file env.example, run"
puts ""
puts " rake setup:dotenv"
puts ""
exit 1
end
# In development, the DATABASE_URL environment variable should be defined in
# the '.env' file. In production, Heroku will set this environment variable
# for you.
DataMapper.setup(:default, ENV["DATABASE_URL"])
# Display DataMapper debugging information in development
if Sinatra::Application.development?
DataMapper::Logger.new($stdout, :debug)
end