Class: Workbench::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/work_bench/application.rb

Overview

Web-server class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Application

Initialize class

Parameters:

  • path (String)

    path to working directory



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/work_bench/application.rb', line 11

def initialize path
  @app = Rack::Builder.new {
    use Rack::Reloader, 0
    use Rack::CommonLogger
    use Rack::ShowExceptions
    use Rack::ContentLength

      # Set config for Compass and SASS
    Compass.configuration do |config|
      config.project_path = path
      config.http_path = '/'
      config.http_images_path = '/img'
      config.http_stylesheets_path = '/css'
      config.http_javascripts_path = '/js'
      config.sass_dir = 'sass'
      config.css_dir = 'public/css'
      config.images_dir = 'public/img'
      config.javascripts_dir = 'public/js'
      config.relative_assets = false
      config.output_style = :compact
      config.line_comments = false
    end

    Compass.configure_sass_plugin!

    use Sass::Plugin::Rack
    use Rack::StaticCache, :urls => [ '/css', '/js', '/img', '/favicon.ico' ], :root => './public', :versioning => false

    run Workbench::DynamicHandler.new path
  }.to_app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/work_bench/application.rb', line 6

def app
  @app
end

Instance Method Details

#start(port, workers) ⇒ Object

Start Unicorn server

Parameters:

  • port (Numeric)

    port number

  • workers (Number)

    workers count



47
48
49
50
51
52
53
# File 'lib/work_bench/application.rb', line 47

def start port, workers
  Unicorn::HttpServer.new(@app, {
    :listeners => [port],
    :worker_processes => workers,
    :preload_app => true
  }).start.join
end