-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.rb
executable file
·63 lines (50 loc) · 1.86 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
Encoding.default_internal = Encoding.default_external = 'UTF-8'
require 'bundler'
Bundler.require
require 'sinatra'
require 'sinatra/flash'
require 'sinatra/custom_logger'
require 'sinatra/json'
require 'active_record'
require 'action_dispatch/middleware/executor'
require 'logger'
require 'socket'
require 'yaml'
environment = Sinatra::Application.environment.to_s
# rubocop:disable Metrics/BlockLength
configure environment.to_sym do
set :root, File.dirname(__FILE__)
set :app_file, __FILE__
set :views, 'app/views'
set :public_folder, 'public'
set :hostname, Socket.gethostname.downcase
register Config
logfile = ::File.join(File.dirname(__FILE__), 'log', 'application.log')
$logger = ::Logger.new(logfile, 'daily')
$logger.level = ::Logger::WARN if environment == 'production'
enable :logging
unless environment == 'production'
enable :dump_errors, :raise_errors, :show_exceptions
require 'sinatra/reloader'
Sinatra::Application.also_reload '/lib/**/*.rb'
Sinatra::Application.also_reload '/app/**/*.rb'
end
cookie_settings = { key: Settings.cookie['key'],
secret: Settings.cookie['secret'],
expire: Settings.cookie['expire'] }
use Rack::Session::Cookie, cookie_settings
use Rack::CommonLogger, $logger
begin
database = YAML.safe_load(ERB.new(File.read('config/database.yml')).result, aliases: true)[environment]
ActiveRecord::Base.logger = $logger
ActiveRecord::Base.establish_connection(database)
use ActionDispatch::Executor, ActiveSupport::Executor
ActiveRecord::QueryCache.install_executor_hooks
rescue StandardError => e
$logger.warn e
end
end
# rubocop:enable Metrics/BlockLength
Dir[File.dirname(__FILE__) + '/lib/**/*.rb'].each { |file| require file }
Dir[File.dirname(__FILE__) + '/app/**/*.rb'].each { |file| require file }