Answer the question
In order to leave comments, you need to log in
Where to store rack application initialization parameters?
Any rack application starts with config.ru, and since there is no single right way in Ruby tm , there are many approaches to organizing this "start point" of the entire project. In my current project, initialization is divided into two files, actually config.ru:
$:.unshift File.expand_path '..', __FILE__
require 'init'
run Awesomeapp
require 'bundler
Bundler.require :default
Mongoid.load! 'db.yml', :development
Dragonfly.app.configure do
datastore :mongoid
end
require 'app/models'
require 'app/lication'
Answer the question
In order to leave comments, you need to log in
config.ru
require_relative 'config/boot'
run Grape::RackBuilder.application
# 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!
Yes, in general, there is nothing wrong, it's just not clear why split into 2 files when there are 10 lines of code :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question