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_relative 'config/environment'
require 'fixer'
require 'rake/testtask' require 'rake/testtask'
require 'db' require 'currency'
require 'fixer'
namespace :rates do namespace :rates do
desc 'Reload all rates' desc 'Reload all rates'

View File

@ -1,3 +1,3 @@
$: << 'lib' require './config/environment'
require 'app' require 'api'
run Sinatra::Application 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 class Currency < Sequel::Model
def self.last_date def self.last_date
order(:date).last.date order(:date).last.date

View File

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

View File

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

View File

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

View File

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