Skip to content

Commit

Permalink
use dotenv to manage env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rahij committed Sep 11, 2015
1 parent 6f8acea commit 459352e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RACK_ENV=development
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ log/

config/*.yml
*.sqlite3
.env
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source 'https://rubygems.org'

gem 'dotenv'

gem 'thin'
gem 'sinatra'
gem 'em-websocket'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GEM
arel (6.0.3)
builder (3.2.2)
daemons (1.2.3)
dotenv (2.0.2)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
Expand Down Expand Up @@ -56,6 +57,7 @@ PLATFORMS
x86-mingw32

DEPENDENCIES
dotenv
em-websocket
file-tail
net-ssh
Expand Down
6 changes: 4 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Rakefile
require 'dotenv/tasks'

require "sinatra/activerecord/rake"
require "sinatra/base"

require 'yaml'

namespace :db do
task :environment do
current_env = Sinatra::Base.environment # RACK_ENV env variable || :development
task :environment => :dotenv do
current_env = ENV['RACK_ENV']
db_config = YAML.load_file('config/database.yml')[current_env.to_s]
ActiveRecord::Base.establish_connection :adapter => db_config["adapter"], :database => db_config["database"]
end
Expand Down
5 changes: 4 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'dotenv'
Dotenv.load

require 'sinatra/base'
require 'sinatra/activerecord'

Expand All @@ -10,7 +13,7 @@
require './models/service'

class App < Sinatra::Base
set :environment, :development
set :environment, ENV['RACK_ENV']
set :public_folder, Proc.new { File.join(root, "public") }
set :views, Proc.new { File.join(root, "templates") }
register Sinatra::ActiveRecordExtension
Expand Down

0 comments on commit 459352e

Please sign in to comment.