-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.rb
executable file
·70 lines (52 loc) · 1.58 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
64
65
66
67
68
69
70
#!/usr/bin/env ruby
if __FILE__ == $0
puts "~ Running as a console."
ENV['RACK_ENV'] ||= 'development'
end
require 'bundler'
require 'yaml'
require 'mysql2'
require 'sequel'
require 'slim'
require 'logger'
require 'redis'
require 'nokogiri'
require 'recursive-open-struct'
require_relative 'lib/hash_dig'
require_relative 'lib/sequel'
unless ENV.has_key?('RACK_ENV')
abort "You have to set RACK_ENV!"
end
config_file = "config/common/config.yaml"
unless File.readable?(config_file)
abort "!!! FATAL: cannot read config file #{config_file}"
end
require 'pry' if ENV['RACK_ENV'] == 'development'
config = YAML.load_file(config_file)
$config = RecursiveOpenStruct.new(config)
$config.config_file = config_file
$config.version = File.read(__dir__ + '/version.txt').chomp
DB = Sequel.connect($config.db.dsn)
DB.extension :connection_validator if [ 'production' ].member?(ENV['RACK_ENV'])
DB.extension :looser_typecasting
Sequel.extension :pagination
Sequel::Model.plugin :json_serializer
Sequel::Model.plugin :serialization_modification_detection
Sequel::Model.plugin :nested_attributes
Sequel::Model.plugin :serialization
Sequel::Model.plugin :timestamps
Sequel::Model.plugin :validation_helpers
# Require local modules
require_relative 'init/models'
if ARGV.first && File.file?(ARGV.first)
load ARGV.first
end
require_relative 'lib/api'
API::Locations.logger = Logger.new(STDOUT)
API::Locations.parse_locations
# If run on its own rather than just being
# required it can be used as a Ruby console.
if __FILE__ == $0
require 'pry'
binding.pry
end