Class: Gemstar::Commands::Server

Inherits:
Command
  • Object
show all
Defined in:
lib/gemstar/commands/server.rb

Constant Summary collapse

DEFAULT_BIND =
"127.0.0.1"
DEFAULT_PORT =
2112
RELOAD_ENV_VAR =
"GEMSTAR_RELOAD_ACTIVE"
RELOAD_GLOB =
"{lib/**/*.rb,lib/gemstar/web/templates/**/*,bin/gemstar,README.md}"
RELOAD_DIRS =
%w[lib bin].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Server

Returns a new instance of Server.



25
26
27
28
29
30
31
32
33
34
# File 'lib/gemstar/commands/server.rb', line 25

def initialize(options)
  super

  @bind = options[:bind] || DEFAULT_BIND
  @explicit_port = !options[:port].nil?
  @port = (options[:port] || DEFAULT_PORT).to_i
  @project_inputs = normalize_project_inputs(options[:project])
  @reload = options[:reload]
  @open_browser = options[:open]
end

Instance Attribute Details

#bindObject (readonly)

Returns the value of attribute bind.



18
19
20
# File 'lib/gemstar/commands/server.rb', line 18

def bind
  @bind
end

#explicit_portObject (readonly)

Returns the value of attribute explicit_port.



23
24
25
# File 'lib/gemstar/commands/server.rb', line 23

def explicit_port
  @explicit_port
end

#open_browserObject (readonly)

Returns the value of attribute open_browser.



22
23
24
# File 'lib/gemstar/commands/server.rb', line 22

def open_browser
  @open_browser
end

#portObject (readonly)

Returns the value of attribute port.



19
20
21
# File 'lib/gemstar/commands/server.rb', line 19

def port
  @port
end

#project_inputsObject (readonly)

Returns the value of attribute project_inputs.



20
21
22
# File 'lib/gemstar/commands/server.rb', line 20

def project_inputs
  @project_inputs
end

#reloadObject (readonly)

Returns the value of attribute reload.



21
22
23
# File 'lib/gemstar/commands/server.rb', line 21

def reload
  @reload
end

Instance Method Details

#runObject



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
# File 'lib/gemstar/commands/server.rb', line 36

def run
  projects = load_projects

  restart_with_rerun if reload_requested?

  require "rackup"
  require "webrick"
  require "gemstar/request_logger"
  require "gemstar/webrick_logger"
  require "gemstar/web/app"

  Gemstar::Config.ensure_home_directory!
  @port = resolve_port

  log_loaded_projects(projects)
  cache_warmer = build_cache_warmer
  web_app = Gemstar::Web::App.build(projects: projects, config_home: Gemstar::Config.home_directory, cache_warmer: cache_warmer)
  cache_warmer.detail_cache_fetcher = build_detail_cache_fetcher(web_app)
  app = web_app
  app = Gemstar::RequestLogger.new(app, io: $stderr) if debug_request_logging?

  puts "Gemstar server listening on http://#{bind}:#{port}"
  puts "Config home: #{Gemstar::Config.home_directory}"
  begin
    Rackup::Server.start(
      app: app,
      server: "webrick",
      Host: bind,
      Port: port,
      AccessLog: [],
      Logger: Gemstar::WEBrickLogger.new($stderr, WEBrick::BasicLog::INFO),
      StartCallback: server_start_callback(projects, cache_warmer)
    )
  ensure
    stop_background_cache_refresh(cache_warmer)
  end
end