Use a minimal app framework

This commit is contained in:
hakanensari 2014-03-14 12:08:48 +00:00
parent 1f9e2f1932
commit 4fdd65ac3c
11 changed files with 37 additions and 14 deletions

View File

@ -1,8 +1,7 @@
$: << 'lib'
require 'fixer'
require_relative 'config/environment'
require 'rake/testtask'
require 'db'
require 'currency'
require 'fixer'
namespace :rates do
desc 'Reload all rates'

View File

@ -1,3 +1,3 @@
$: << 'lib'
require 'app'
require './config/environment'
require 'api'
run Sinatra::Application

18
config/app.rb Normal file
View File

@ -0,0 +1,18 @@
require 'logger'
require 'pathname'
module App
class << self
attr :logger
def env
ENV['RACK_ENV'] || 'development'
end
def root
Pathname.pwd
end
end
@logger = Logger.new(STDOUT)
end

3
config/environment.rb Normal file
View File

@ -0,0 +1,3 @@
require_relative 'app'
$LOAD_PATH << App.root.join('lib')
Dir[App.root.join('config/initializers/*.rb')].each { |f| require f }

View File

@ -0,0 +1,5 @@
require 'pg'
require 'sequel'
Sequel.single_threaded = true
Sequel.connect(ENV['DATABASE_URL'] || "postgres://localhost/fixer_#{App.env}")

View File

@ -1,7 +1,3 @@
require 'sequel'
Sequel.connect ENV['DATABASE_URL'] || 'postgres://localhost/fixer'
class Currency < Sequel::Model
def self.last_date
order(:date).last.date

View File

@ -1,5 +1,5 @@
require 'virtus'
require 'db'
require 'currency'
class Snapshot
include Virtus

View File

@ -1,8 +1,8 @@
require_relative 'helper'
require 'rack/test'
require 'app'
require 'api'
describe 'the application' do
describe 'the API' do
include Rack::Test::Methods
let(:app) { Sinatra::Application }

View File

@ -1,6 +1,6 @@
require_relative 'helper'
require 'rack/test'
require 'app'
require 'server'
if ENV['BENCH']
describe 'benchmark the app' do

View File

@ -1,3 +1,5 @@
ENV['RACK_ENV'] = 'test'
require './config/environment'
require 'minitest/autorun'
require 'minitest/benchmark' if ENV['BENCH']
require 'minitest/pride'