Class: JsSpec::Server

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

Direct Known Subclasses

RailsServer

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec_root_path, implementation_root_path, public_path, host = DEFAULT_HOST, port = DEFAULT_PORT) ⇒ Server

Returns a new instance of Server.



25
26
27
28
29
30
31
32
33
# File 'lib/js_spec/server.rb', line 25

def initialize(spec_root_path, implementation_root_path, public_path, host=DEFAULT_HOST, port=DEFAULT_PORT)
  dir = ::File.dirname(__FILE__)
  @core_path = ::File.expand_path("#{dir}/../../core")
  @spec_root_path = ::File.expand_path(spec_root_path)
  @implementation_root_path = ::File.expand_path(implementation_root_path)
  @public_path = ::File.expand_path(public_path)
  @host = host
  @port = port
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



4
5
6
# File 'lib/js_spec/server.rb', line 4

def instance
  @instance
end

Instance Attribute Details

#core_pathObject (readonly)

Returns the value of attribute core_path.



23
24
25
# File 'lib/js_spec/server.rb', line 23

def core_path
  @core_path
end

#hostObject (readonly)

Returns the value of attribute host.



23
24
25
# File 'lib/js_spec/server.rb', line 23

def host
  @host
end

#implementation_root_pathObject (readonly)

Returns the value of attribute implementation_root_path.



23
24
25
# File 'lib/js_spec/server.rb', line 23

def implementation_root_path
  @implementation_root_path
end

#portObject (readonly)

Returns the value of attribute port.



23
24
25
# File 'lib/js_spec/server.rb', line 23

def port
  @port
end

#public_pathObject (readonly)

Returns the value of attribute public_path.



23
24
25
# File 'lib/js_spec/server.rb', line 23

def public_path
  @public_path
end

#spec_root_pathObject (readonly)

Returns the value of attribute spec_root_path.



23
24
25
# File 'lib/js_spec/server.rb', line 23

def spec_root_path
  @spec_root_path
end

Class Method Details

.connectionObject



17
# File 'lib/js_spec/server.rb', line 17

def connection; instance.connection; end

.core_pathObject



16
# File 'lib/js_spec/server.rb', line 16

def core_path; instance.core_path; end

.implementation_root_pathObject



14
# File 'lib/js_spec/server.rb', line 14

def implementation_root_path; instance.implementation_root_path; end

.public_pathObject



15
# File 'lib/js_spec/server.rb', line 15

def public_path; instance.public_path; end

.requestObject



18
# File 'lib/js_spec/server.rb', line 18

def request; instance.request; end

.responseObject



19
# File 'lib/js_spec/server.rb', line 19

def response; instance.response; end

.root_urlObject



20
# File 'lib/js_spec/server.rb', line 20

def root_url; instance.root_url; end

.run(spec_root_path, implementation_root_path, public_path, server_options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/js_spec/server.rb', line 6

def run(spec_root_path, implementation_root_path, public_path, server_options = {})
  server_options[:Host] ||= DEFAULT_HOST
  server_options[:Port] ||= DEFAULT_PORT
  @instance = new(spec_root_path, implementation_root_path, public_path, server_options[:Host], server_options[:Port])
  instance.run server_options
end

.spec_root_pathObject



13
# File 'lib/js_spec/server.rb', line 13

def spec_root_path; instance.spec_root_path; end

Instance Method Details

#call(env) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/js_spec/server.rb', line 42

def call(env)
  self.connection = env['js_spec.connection']
  self.request = Rack::Request.new(env)
  self.response = Rack::Response.new
  method = request.request_method.downcase.to_sym
  get_resource(request).send(method, request, response)
  response.finish
ensure
  self.connection = nil
  self.request = nil
  self.response = nil
end

#connectionObject



55
56
57
# File 'lib/js_spec/server.rb', line 55

def connection
  Thread.current[:connection]
end

#requestObject



59
60
61
# File 'lib/js_spec/server.rb', line 59

def request
  Thread.current[:request]
end

#responseObject



63
64
65
# File 'lib/js_spec/server.rb', line 63

def response
  Thread.current[:response]
end

#root_urlObject



67
68
69
# File 'lib/js_spec/server.rb', line 67

def root_url
  "http://#{host}:#{port}"
end

#run(options) ⇒ Object



35
36
37
38
39
40
# File 'lib/js_spec/server.rb', line 35

def run(options)
  server = ::Thin::Server.new(options[:Host], options[:Port], self)
  server.backend = ::Thin::Backends::JsSpecServer.new(options[:Host], options[:Port])
  server.backend.server = server
  server.start!
end