Class: Stickler::Middleware::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/stickler/middleware/server.rb

Overview

Server is the entire stickler stack as a single piece of middleware that may be used by other libraries that would like to include Stickler in their application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Server

Returns a new instance of Server.



9
10
11
12
13
14
# File 'lib/stickler/middleware/server.rb', line 9

def initialize( app, opts = {} )
  @app            = app
  @stickler_root  = Pathname.new( opts.fetch( :stickler_root ) ).realpath
  @run            = server_app
  validate
end

Instance Attribute Details

#stickler_rootObject (readonly)

Returns the value of attribute stickler_root.



7
8
9
# File 'lib/stickler/middleware/server.rb', line 7

def stickler_root
  @stickler_root
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
# File 'lib/stickler/middleware/server.rb', line 16

def call( env )
  @run.call( env )
end

#server_appObject



20
21
22
23
24
25
26
27
28
# File 'lib/stickler/middleware/server.rb', line 20

def server_app
  root = self.stickler_root
  Rack::Builder.app( @app )do
    use Stickler::Middleware::Compression
    use Stickler::Middleware::Gemcutter, :serve_indexes => false, :repo_root => root.join( "gemcutter" )
    use Stickler::Middleware::Mirror,    :serve_indexes => false, :repo_root => root.join( "mirror" )
    use Stickler::Middleware::Index,     :serve_indexes => true
  end
end