Class: Pieces::Server

Inherits:
Rack::Server
  • Object
show all
Defined in:
lib/pieces/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



8
9
10
11
# File 'lib/pieces/server.rb', line 8

def initialize(options = {})
  @path = options[:path] || Dir.pwd
  super
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/pieces/server.rb', line 6

def path
  @path
end

Instance Method Details

#appObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pieces/server.rb', line 18

def app
  files = files_to_serve(path)
  build_path = "#{path}/build"

  Rack::Builder.app do
    use Rack::Reloader

    use Rack::Static, urls: files,
                      root: build_path,
                      index: 'index.html'

    run Proc.new { |env| [404, {}, ['Not found']] }
  end
end

#startObject



13
14
15
16
# File 'lib/pieces/server.rb', line 13

def start
  Pieces::Listener.new(path: path).listen
  super
end