Class: Gemstar::Commands::Server
- 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
-
#bind ⇒ Object
readonly
Returns the value of attribute bind.
-
#explicit_port ⇒ Object
readonly
Returns the value of attribute explicit_port.
-
#open_browser ⇒ Object
readonly
Returns the value of attribute open_browser.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#project_inputs ⇒ Object
readonly
Returns the value of attribute project_inputs.
-
#reload ⇒ Object
readonly
Returns the value of attribute reload.
Instance Method Summary collapse
-
#initialize(options) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
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() super @bind = [:bind] || DEFAULT_BIND @explicit_port = ![:port].nil? @port = ([:port] || DEFAULT_PORT).to_i @project_inputs = normalize_project_inputs([:project]) @reload = [:reload] @open_browser = [:open] end |
Instance Attribute Details
#bind ⇒ Object (readonly)
Returns the value of attribute bind.
18 19 20 |
# File 'lib/gemstar/commands/server.rb', line 18 def bind @bind end |
#explicit_port ⇒ Object (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_browser ⇒ Object (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 |
#port ⇒ Object (readonly)
Returns the value of attribute port.
19 20 21 |
# File 'lib/gemstar/commands/server.rb', line 19 def port @port end |
#project_inputs ⇒ Object (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 |
#reload ⇒ Object (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
#run ⇒ Object
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 |