config.ru
require_relative 'config/boot'
run Grape::RackBuilder.application
config/boot.rb
# Defines our constants
RACK_ENV = ENV['RACK_ENV'] || 'development' unless defined?(RACK_ENV)
APP_ROOT = File.expand_path('../..', __FILE__) unless defined?(APP_ROOT)
# Load our dependencies
require 'rubygems' unless defined?(Gem)
require 'bundler/setup'
# Load initializers
Bundler.require(:default, RACK_ENV)
require_relative 'settings'
ApplicationSettings.source File.expand_path('config/application.yml', APP_ROOT)
ApplicationSettings.root = APP_ROOT
require_relative 'database'
Dir[File.join(File.dirname(__FILE__),'initializers/**/*.rb')].each {|file_name| require file_name}
Rabl.configure do |config|
config.include_json_root = false
end
Grape::RackBuilder.setup do
%w{api models lib uploaders models abilities jobs search_indexes}.each do |path|
add_source_path ApplicationSettings.root("#{path}/**/*.rb")
add_source_path ApplicationSettings.root("#{path}/*.rb")
end
use Warden::Manager do |config|
config.strategies.add(:public_access_token, PublicTokenStrategy)
config.default_strategies :public_access_token
config.failure_app = API::Application
config.intercept_401 = false
end
use Rack::Config do |env|
env['api.tilt.root'] = ApplicationSettings.root('rabl')
end
mount 'API::Application', to: '/api'
logger ApplicationSettings.logger(:rackbuilder)
end.boot!
Помимо config.ru инициализация приложения нужна также и в spec_helper для тестирования. Поэтому разбивать обязательно.