Class: Awestruct::CLI::Server
- Inherits:
-
Object
- Object
- Awestruct::CLI::Server
- Defined in:
- lib/awestruct/cli/server.rb
Instance Attribute Summary collapse
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(path, bind_addr = Options::DEFAULT_BIND_ADDR, port = Options::DEFAULT_PORT, generate_on_access = Options::DEFAULT_GENERATE_ON_ACCESS) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(path, bind_addr = Options::DEFAULT_BIND_ADDR, port = Options::DEFAULT_PORT, generate_on_access = Options::DEFAULT_GENERATE_ON_ACCESS) ⇒ Server
Returns a new instance of Server.
14 15 16 17 18 19 |
# File 'lib/awestruct/cli/server.rb', line 14 def initialize(path, bind_addr=Options::DEFAULT_BIND_ADDR, port=Options::DEFAULT_PORT, generate_on_access=Options::DEFAULT_GENERATE_ON_ACCESS) @path = path @bind_addr = bind_addr @port = port @generate_on_access = generate_on_access end |
Instance Attribute Details
#server ⇒ Object (readonly)
Returns the value of attribute server.
12 13 14 |
# File 'lib/awestruct/cli/server.rb', line 12 def server @server end |
Instance Method Details
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/awestruct/cli/server.rb', line 21 def run unless port_open? @bind_addr, @port $LOG.error "#{@bind_addr}:#{@port} not available for server" abort end url = %(http://#{@bind_addr}:#{@port}) msg = %(Starting preview server at #{url} (Press Ctrl-C to shutdown)) $LOG.info %(#{'*' * msg.length}\n#{msg}\n#{'*' * msg.length}\n) path = @path generate_on_access = @generate_on_access app = ::Rack::Builder.new do use Awestruct::Rack::GenerateOnAccess if generate_on_access use Awestruct::Rack::Debug map "/" do run Awestruct::Rack::App.new( path ) end end ::Rack::Server::start(:app => app, :Port => @port, :Host => @bind_addr ) end |