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' ...@@ -11,8 +11,15 @@ gem 'sinatra-activerecord'
gem 'puma' gem 'puma'
gem 'tux' gem 'tux'
# These gems are only installed when run as `bundle install --without production`
group :development, :test do group :development, :test do
gem 'pry' gem 'pry'
gem 'shotgun' gem 'shotgun'
gem 'sqlite3' gem 'sqlite3'
end 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 ...@@ -24,6 +24,7 @@ GEM
method_source (0.8.2) method_source (0.8.2)
minitest (5.8.3) minitest (5.8.3)
multi_json (1.11.2) multi_json (1.11.2)
pg (0.18.4)
pry (0.10.3) pry (0.10.3)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
...@@ -76,6 +77,7 @@ PLATFORMS ...@@ -76,6 +77,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
activesupport activesupport
pg
pry pry
puma puma
rake rake
...@@ -85,3 +87,6 @@ DEPENDENCIES ...@@ -85,3 +87,6 @@ DEPENDENCIES
sinatra-contrib sinatra-contrib
sqlite3 sqlite3
tux tux
BUNDLED WITH
1.12.1
...@@ -2,20 +2,6 @@ require 'rake' ...@@ -2,20 +2,6 @@ require 'rake'
require "sinatra/activerecord/rake" require "sinatra/activerecord/rake"
require ::File.expand_path('../config/environment', __FILE__) 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' desc 'Retrieves the current schema version number'
task "db:version" do task "db:version" do
puts "Current version: #{ActiveRecord::Migrator.current_version}" puts "Current version: #{ActiveRecord::Migrator.current_version}"
......
...@@ -2,4 +2,3 @@ ...@@ -2,4 +2,3 @@
get '/' do get '/' do
erb :index erb :index
end end
configure do
# Log queries to STDOUT in development configure :development do
if Sinatra::Application.development?
ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Base.logger = Logger.new(STDOUT)
end end
configure :development, :test do
set :database, { set :database, {
adapter: "sqlite3", adapter: 'sqlite3',
database: "db/db.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 # Load all models from app/models, using autoload instead of require
# See http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html # See http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html
Dir[APP_ROOT.join('app', 'models', '*.rb')].each do |model_file| Dir[APP_ROOT.join('app', 'models', '*.rb')].each do |model_file|
filename = File.basename(model_file).gsub('.rb', '') filename = File.basename(model_file).gsub('.rb', '')
autoload ActiveSupport::Inflector.camelize(filename), model_file autoload ActiveSupport::Inflector.camelize(filename), model_file
end end
end end
...@@ -8,12 +8,10 @@ require 'sinatra' ...@@ -8,12 +8,10 @@ require 'sinatra'
require 'sinatra/activerecord' require 'sinatra/activerecord'
require 'sinatra/contrib/all' # Requires cookies, among other things require 'sinatra/contrib/all' # Requires cookies, among other things
require 'pry'
APP_ROOT = Pathname.new(File.expand_path('../../', __FILE__)) APP_ROOT = Pathname.new(File.expand_path('../../', __FILE__))
APP_NAME = APP_ROOT.basename.to_s APP_NAME = APP_ROOT.basename.to_s
# Sinatra configuration # Global Sinatra configuration
configure do configure do
set :root, APP_ROOT.to_path set :root, APP_ROOT.to_path
set :server, :puma set :server, :puma
...@@ -24,6 +22,16 @@ configure do ...@@ -24,6 +22,16 @@ configure do
set :views, File.join(Sinatra::Application.root, "app", "views") set :views, File.join(Sinatra::Application.root, "app", "views")
end 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 # Set up the database and models
require APP_ROOT.join('config', 'database') 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