Skip to content
Browse files

Simplify environment settings with dotenv

  • Loading branch information...
1 parent 50d292d commit e1e3b1504d5cb9141937558b4479e0da683df086 @chischaschos committed
Showing with 18 additions and 36 deletions.
  1. +6 −0 .env.development
  2. +6 −0 .env.test
  3. +3 −31 config.rb
  4. +1 −2 main.rb
  5. +2 −3 spec/base.rb
View
6 .env.development
@@ -0,0 +1,6 @@
+DATABASE_URL=sqlite://blog.db
+PORT=9393
+BLOG_PASSWD=123
+COOKIE_KEY=123
+COOKIE_VALUE=123
+DISQUS_SHORTNAME=me
View
6 .env.test
@@ -0,0 +1,6 @@
+DATABASE_URL=sqlite:/
+PORT=9393
+BLOG_PASSWD=123
+COOKIE_KEY=123
+COOKIE_VALUE=123
+DISQUS_SHORTNAME=me
View
34 config.rb
@@ -9,7 +9,7 @@ module Config
AUTHOR = 'ed'
def self.registered app
- app.configure :production do
+ app.configure do
raise "DATABASE_URL not set" unless ENV['DATABASE_URL']
raise "BLOG_PASSWD not set" unless ENV['BLOG_PASSWD']
@@ -20,8 +20,8 @@ def self.registered app
app.set :db, Sequel.connect(ENV['DATABASE_URL'])
app.set :blog, OpenStruct.new(
- title: TITLE,
- author: AUTHOR,
+ title: 'chischaschos',
+ author: 'ed',
url_base: 'http://emmanueldelgado.me',
admin_password: ENV['BLOG_PASSWD'],
admin_cookie_key: ENV['COOKIE_KEY'],
@@ -30,34 +30,6 @@ def self.registered app
)
end
- app.configure :development do
- app.set :db, Sequel.connect('sqlite://blog.db')
-
- app.set :blog, OpenStruct.new(
- title: TITLE,
- author: AUTHOR,
- url_base: 'http://localhost/',
- admin_password: '123',
- admin_cookie_key: '123',
- admin_cookie_value: '123',
- disqus_shortname: '123'
- )
- end
-
- app.configure :test do
- app.set :db, Sequel.sqlite
-
- app.set :blog, OpenStruct.new(
- title: TITLE,
- author: AUTHOR,
- url_base: 'http://localhost/',
- admin_password: '123',
- admin_cookie_key: '123',
- admin_cookie_value: '123',
- disqus_shortname: '123'
- )
- end
-
app.error do
e = request.env['sinatra.error']
puts e.to_s
View
3 main.rb
@@ -2,7 +2,7 @@
require 'bundler'
Bundler.require :default
-Dotenv.load
+Dotenv.load! ".env.#{ENV['RACK_ENV'].downcase}"
require_relative 'config'
require_relative 'helpers'
@@ -15,7 +15,6 @@ class App < Sinatra::Base
set :root, File.realdirpath('.')
set :run, false
- set :env, ENV['RACK_ENV'] || 'development'
set :sprockets, Sinatra::Blogging::Assets.environment(settings.root)
set :manifest, Sprockets::Manifest.new(settings.sprockets, './public/assets')
View
5 spec/base.rb
@@ -1,10 +1,10 @@
require 'rubygems'
require 'bundler'
-$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-
ENV['RACK_ENV'] = 'test'
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
+
require 'simplecov'
SimpleCov.start
@@ -17,7 +17,6 @@
Capybara.javascript_driver = :webkit
Capybara.app = Sinatra::Blogging::App
-
RSpec.configure do |config|
config.after do

0 comments on commit e1e3b15

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