Commit 526c9ebe authored by James S's avatar James S

Merge pull request #5 from lighthouse-labs/deployable

Updates to follow better practices with environment and heroku deployability
parents 73e3a7d1 31b73b6b
......@@ -11,8 +11,15 @@ gem 'sinatra-activerecord'
gem 'puma'
gem 'tux'
# These gems are only installed when run as `bundle install --without production`
group :development, :test do
gem 'pry'
gem 'shotgun'
gem 'sqlite3'
end
# bundle install --without test --without development
group :production do
# use postgres in production, or move outside a group if your app uses postgres for development and production
gem 'pg'
end
......@@ -24,6 +24,7 @@ GEM
method_source (0.8.2)
minitest (5.8.3)
multi_json (1.11.2)
pg (0.18.4)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
......@@ -76,6 +77,7 @@ PLATFORMS
DEPENDENCIES
activesupport
pg
pry
puma
rake
......@@ -85,3 +87,6 @@ DEPENDENCIES
sinatra-contrib
sqlite3
tux
BUNDLED WITH
1.12.1
......@@ -2,20 +2,6 @@ require 'rake'
require "sinatra/activerecord/rake"
require ::File.expand_path('../config/environment', __FILE__)
Rake::Task["db:create"].clear
Rake::Task["db:drop"].clear
# NOTE: Assumes SQLite3 DB
desc "create the database"
task "db:create" do
touch 'db/db.sqlite3'
end
desc "drop the database"
task "db:drop" do
rm_f 'db/db.sqlite3'
end
desc 'Retrieves the current schema version number'
task "db:version" do
puts "Current version: #{ActiveRecord::Migrator.current_version}"
......
......@@ -2,4 +2,3 @@
get '/' do
erb :index
end
configure do
# Log queries to STDOUT in development
if Sinatra::Application.development?
configure :development do
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
end
configure :development, :test do
set :database, {
adapter: "sqlite3",
database: "db/db.sqlite3"
adapter: 'sqlite3',
database: APP_ROOT.join('db', "#{Sinatra::Application.environment}.sqlite3")
}
end
configure :production do
# Database connection is configured automatically based on the DATABASE_URL
# environment variable. This is a feature of sinatra/activerecord support.
#
# If you're deploying to Heroku this will be set automatically.
end
configure do
# Load all models from app/models, using autoload instead of require
# See http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html
Dir[APP_ROOT.join('app', 'models', '*.rb')].each do |model_file|
filename = File.basename(model_file).gsub('.rb', '')
autoload ActiveSupport::Inflector.camelize(filename), model_file
end
end
......@@ -8,12 +8,10 @@ require 'sinatra'
require 'sinatra/activerecord'
require 'sinatra/contrib/all' # Requires cookies, among other things
require 'pry'
APP_ROOT = Pathname.new(File.expand_path('../../', __FILE__))
APP_NAME = APP_ROOT.basename.to_s
# Sinatra configuration
# Global Sinatra configuration
configure do
set :root, APP_ROOT.to_path
set :server, :puma
......@@ -24,6 +22,16 @@ configure do
set :views, File.join(Sinatra::Application.root, "app", "views")
end
# Development and Test Sinatra Configuration
configure :development, :test do
require 'pry'
end
# Production Sinatra Configuration
configure :production do
# NOOP
end
# Set up the database and models
require APP_ROOT.join('config', 'database')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment