forked from hanami/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
56 lines (48 loc) · 1.17 KB
/
server.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
# frozen_string_literal: true
module Hanami
module CLI
# @since 2.0.0
# @api private
class Server
# @since 2.0.0
# @api private
attr_reader :rack_server
# @since 2.0.0
# @api private
RACK_FALLBACK_OPTIONS = {
host: :Host,
port: :Port
}.freeze
# @since 2.0.0
# @api private
OVERRIDING_OPTIONS = {
config: :config,
debug: :debug,
warn: :warn
}.freeze
# @since 2.0.0
# @api private
def initialize(rack_server: Rackup::Server)
@rack_server = rack_server
end
# @since 2.0.0
# @api private
def call(**options)
rack_server.start(Hash[
extract_rack_fallback_options(options) + extract_overriding_options(options)
])
end
private
def extract_rack_fallback_options(options)
RACK_FALLBACK_OPTIONS.filter_map do |(name, rack_name)|
options[name] && [rack_name, options[name]]
end
end
def extract_overriding_options(options)
OVERRIDING_OPTIONS.map do |(name, rack_name)|
[rack_name, options[name]]
end
end
end
end
end