Class: CommunityZero::Server
- Inherits:
-
Object
- Object
- CommunityZero::Server
- Defined in:
- lib/community_zero/server.rb
Overview
A single instance of the Community Server.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :host => '0.0.0.0', :port => 3000 }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
The list of options passed to the server.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
Create a new Community site server.
-
#running? ⇒ Boolean
Determine if the server is currently running.
-
#start ⇒ Thread
Start the community server.
-
#url ⇒ Object
Returns the URL the server is listening on.
Constructor Details
#initialize(options = {}) ⇒ Server
Create a new Community site server.
44 45 46 |
# File 'lib/community_zero/server.rb', line 44 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Hash (readonly)
The list of options passed to the server.
33 34 35 |
# File 'lib/community_zero/server.rb', line 33 def @options end |
Instance Method Details
#running? ⇒ Boolean
Determine if the server is currently running.
71 72 73 |
# File 'lib/community_zero/server.rb', line 71 def running? server && server.running? end |
#start ⇒ Thread
Start the community server.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/community_zero/server.rb', line 52 def start if [:publish] puts ">> Starting Community Zero (v#{CommunityZero::VERSION})..." puts ">> Puma (v#{Puma::Const::PUMA_VERSION}) is listening at #{url}" puts ">> Press CTRL+C to stop" end begin thread = server.run.join rescue Object, Interrupt puts "\n>> Stopping Puma..." if [:publish] server.stop(true) if running? end end |
#url ⇒ Object
Returns the URL the server is listening on.
84 85 86 |
# File 'lib/community_zero/server.rb', line 84 def url @url ||= "http://#{[:host]}:#{[:port]}" end |