Class: Munge::Cli::Commands::View

Inherits:
Object
  • Object
show all
Defined in:
lib/munge/cli/commands/view.rb

Instance Method Summary collapse

Constructor Details

#initialize(bootloader, host:, port:, build_root: nil) ⇒ View

Returns a new instance of View.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/munge/cli/commands/view.rb', line 31

def initialize(bootloader, host:, port:, build_root: nil)
  config = bootloader.config
  @host  = host
  @port  = port
  root   = File.expand_path(build_root || config[:output], bootloader.root_path)

  @app =
    Rack::Builder.new do
      use Rack::ShowExceptions
      use Rack::Head
      use Adsf::Rack::IndexFileFinder, root: root
      run Rack::File.new(root)
    end
end

Instance Method Details

#callObject



46
47
48
49
50
51
52
53
54
# File 'lib/munge/cli/commands/view.rb', line 46

def call
  Signal.trap("INT") do
    # Prints a newline after the terminal prints `^C`
    puts
    Rack::Handler::WEBrick.shutdown
  end

  Rack::Handler::WEBrick.run(@app, Host: @host, Port: @port)
end