Class: Contracted::Application

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

Constant Summary collapse

APPLICATION_START_TIMEOUT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, port) ⇒ Application

Returns a new instance of Application.



18
19
20
21
22
23
24
# File 'lib/contracted/application.rb', line 18

def initialize app, port
  @app = app
  @host = "0.0.0.0"
  @port = port
  @server = Thin::Server.new(host, port.to_s) { run app }
  mount
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



16
17
18
# File 'lib/contracted/application.rb', line 16

def app
  @app
end

#hostObject (readonly)

Returns the value of attribute host.



16
17
18
# File 'lib/contracted/application.rb', line 16

def host
  @host
end

#lastObject (readonly)

Returns the value of attribute last.



16
17
18
# File 'lib/contracted/application.rb', line 16

def last
  @last
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/contracted/application.rb', line 16

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



16
17
18
# File 'lib/contracted/application.rb', line 16

def server
  @server
end

Instance Method Details

#get(url, body, headers) ⇒ Object



44
45
46
# File 'lib/contracted/application.rb', line 44

def get url, body, headers
  @last = RestClient.get("#{host_and_port}#{url}", headers)
end

#host_and_portObject



26
27
28
# File 'lib/contracted/application.rb', line 26

def host_and_port
  "#{host}:#{port}"
end

#mountObject



35
36
37
38
39
40
41
42
# File 'lib/contracted/application.rb', line 35

def mount
  @server_thread = Thread.start do
    server.start
  end
  Timeout.timeout(APPLICATION_START_TIMEOUT) do
    loop_until { server.running? }
  end
end

#unmountObject



30
31
32
33
# File 'lib/contracted/application.rb', line 30

def unmount
  @server.stop
  @server_thread.terminate
end