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.



22
23
24
25
26
27
28
29
30
31
# File 'lib/gemstar/commands/server.rb', line 22

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.



15
16
17
# File 'lib/gemstar/commands/server.rb', line 15

def bind
  @bind
end

#explicit_portObject (readonly)

Returns the value of attribute explicit_port.



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

def explicit_port
  @explicit_port
end

#open_browserObject (readonly)

Returns the value of attribute open_browser.



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

def open_browser
  @open_browser
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/gemstar/commands/server.rb', line 16

def port
  @port
end

#project_inputsObject (readonly)

Returns the value of attribute project_inputs.



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

def project_inputs
  @project_inputs
end

#reloadObject (readonly)

Returns the value of attribute reload.



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

def reload
  @reload
end

Instance Method Details

#runObject



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

def run
  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

  projects = load_projects
  log_loaded_projects(projects)
  cache_warmer = build_cache_warmer
  app = Gemstar::Web::App.build(projects: projects, config_home: Gemstar::Config.home_directory, cache_warmer: cache_warmer)
  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}"
  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)
  )
end