Class: Jasmine::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, config) ⇒ Server

Returns a new instance of Server.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/jasmine/server.rb', line 86

def initialize(port, config)
  @port = port
  @config = config

  require 'thin'
  thin_config = {
    '/__suite__' => Jasmine::FocusedSuite.new(@config),
    '/run.html' => Jasmine::Redirect.new('/'),
    '/' => Jasmine::RunAdapter.new(@config)
  }

  @config.mappings.each do |from, to|
    thin_config[from] = Rack::File.new(to)
  end

  thin_config["/__JASMINE_ROOT__"] = Rack::File.new(Jasmine.root)

  app = Rack::Cascade.new([
    Rack::URLMap.new({'/' => Rack::File.new(@config.src_dir)}),
    Rack::URLMap.new(thin_config),
    JsAlert.new
  ])

  @thin = Thin::Server.new('0.0.0.0', @port, app)
end

Instance Attribute Details

#thinObject (readonly)

Returns the value of attribute thin.



84
85
86
# File 'lib/jasmine/server.rb', line 84

def thin
  @thin
end

Instance Method Details

#startObject



112
113
114
115
116
117
118
119
# File 'lib/jasmine/server.rb', line 112

def start
  begin
    thin.start
  rescue RuntimeError => e
    raise e unless e.message == 'no acceptor'
    raise RuntimeError.new("A server is already running on port #{@port}")
  end
end

#stopObject



121
122
123
# File 'lib/jasmine/server.rb', line 121

def stop
  thin.stop
end