-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplication.rb
81 lines (60 loc) · 1.67 KB
/
application.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
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true
## Require gems
require 'bundler/setup'
Bundler.require(
:system, :server, :database, :translations, :forms, :views, :assets, :mails, :auth, :others
)
require 'erubi/capture_end'
require 'voight_kampff/rack_request'
## Require libs
### For $RS constant:
### http://ruby-doc.org/stdlib/libdoc/English/rdoc/English.html
require 'English'
require 'logger'
# require 'money/bank/google_currency'
require_relative 'constants'
module StreamTimer
## Class for application
class Application < Flame::Application
class << self
include Memery
memoize def logger
::Logger.new(
development_or_toys ? $stdout : File.join(config[:stdout_file])
)
end
def db_connection
connection = ::Sequel.connect config[:database]
Config::Processors::Sequel::EXTENSIONS.each do |extension_name|
connection.extension extension_name
end
connection.loggers << logger if development_or_toys
## Freeze DB (not for `toys console`)
connection.freeze unless ENV['RACK_CONSOLE']
connection
end
memoize :db_connection
memoize def shrine_uploaders
{
# image: Class.new(::Shrine),
# document: Class.new(::Shrine)
}
end
def setup
## Initialize Sequel connection before models requiring
db_connection
## Require dirs
require_dirs APP_DIRS, ignore: [%r{config/puma.rb}, %r{lib/\w+/spec/}]
class_exec do
mount Site::Public, '/'
mount Site::TimerController, '/timer'
end
end
private
memoize def development_or_toys
(config[:environment] == 'development') || (File.basename($PROGRAM_NAME) == 'toys')
end
end
require "#{config[:config_dir]}/main"
end
end