summaryrefslogtreecommitdiff
path: root/new/bin/server.rb
blob: 61f7c22d028263377802ded1680aa01a7bd74051 (plain)
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
require_relative "../lib/crys"

module Crys
  class ServerRunner
    SPLASH = [
      <<-HEREDOC
 ▄████▄   ██▀███  ▓██   ██▓  ██████   ██████  ██▓▄▄▄█████▓▓█████ 
▒██▀ ▀█  ▓██ ▒ ██▒ ▒██  ██▒▒██    ▒ ▒██    ▒ ▓██▒▓  ██▒ ▓▒▓█   ▀ 
▒▓█    ▄ ▓██ ░▄█ ▒  ▒██ ██░░ ▓██▄   ░ ▓██▄   ▒██▒▒ ▓██░ ▒░▒███   
▒▓▓▄ ▄██▒▒██▀▀█▄    ░ ▐██▓░  ▒   ██▒  ▒   ██▒░██░░ ▓██▓ ░ ▒▓█  ▄ 
▒ ▓███▀ ░░██▓ ▒██▒  ░ ██▒▓░▒██████▒▒▒██████▒▒░██░  ▒██▒ ░ ░▒████▒
░ ░▒ ▒  ░░ ▒▓ ░▒▓░   ██▒▒▒ ▒ ▒▓▒ ▒ ░▒ ▒▓▒ ▒ ░░▓    ▒ ░░   ░░ ▒░ ░
  ░  ▒     ░▒ ░ ▒░ ▓██ ░▒░ ░ ░▒  ░ ░░ ░▒  ░ ░ ▒ ░    ░     ░ ░  ░
░          ░░   ░  ▒ ▒ ░░  ░  ░  ░  ░  ░  ░   ▒ ░  ░         ░   
░ ░         ░      ░ ░           ░        ░   ░              ░  ░
░                  ░ ░                                           
HEREDOC
    ]

    def initialize(server_class:, root: )
      @root = File.expand_path root
      @server = server_class.new(root: root)
    end

    def serve
      puts ""
      puts SPLASH.sample
      puts "Serving from: " + root
      puts ""
      server.start
    end

    private

    attr_reader :root, :server
  end
end