Class: Contracted::Application
- Inherits:
-
Object
- Object
- Contracted::Application
- Defined in:
- lib/contracted/application.rb
Constant Summary collapse
- APPLICATION_START_TIMEOUT =
5
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #get(url, body, headers) ⇒ Object
- #host_and_port ⇒ Object
-
#initialize(app, port) ⇒ Application
constructor
A new instance of Application.
- #mount ⇒ Object
- #unmount ⇒ Object
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
#app ⇒ Object (readonly)
Returns the value of attribute app.
16 17 18 |
# File 'lib/contracted/application.rb', line 16 def app @app end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
16 17 18 |
# File 'lib/contracted/application.rb', line 16 def host @host end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
16 17 18 |
# File 'lib/contracted/application.rb', line 16 def last @last end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
16 17 18 |
# File 'lib/contracted/application.rb', line 16 def port @port end |
#server ⇒ Object (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_port ⇒ Object
26 27 28 |
# File 'lib/contracted/application.rb', line 26 def host_and_port "#{host}:#{port}" end |
#mount ⇒ Object
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 |
#unmount ⇒ Object
30 31 32 33 |
# File 'lib/contracted/application.rb', line 30 def unmount @server.stop @server_thread.terminate end |