-
Notifications
You must be signed in to change notification settings - Fork 9
/
models.rb
29 lines (22 loc) · 862 Bytes
/
models.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
# frozen_string_literal: true
require_relative 'config/db'
require 'sequel/model'
Sequel::Model.cache_associations = false if ENV['RACK_ENV'] == 'development'
Sequel::Model.plugin :auto_validations
Sequel::Model.plugin :prepared_statements
Sequel::Model.plugin :subclasses unless ENV['RACK_ENV'] == 'development'
unless defined?(Unreloader)
require 'rack/unreloader'
Unreloader = Rack::Unreloader.new(reload: false)
end
Unreloader.require('models') { |f| Sequel::Model.send(:camelize, File.basename(f).delete_suffix('.rb')) }
if ENV['RACK_ENV'] == 'development' || ENV['RACK_ENV'] == 'test'
require 'logger'
LOGGER = Logger.new($stdout)
LOGGER.level = Logger::FATAL if ENV['RACK_ENV'] == 'test'
Config::DB.connect.loggers << LOGGER
end
unless ENV['RACK_ENV'] == 'development'
Sequel::Model.freeze_descendents
Config::DB.connect.freeze
end