Class: Rapid::App

Inherits:
Object
  • Object
show all
Defined in:
lib/ury_rapid/app.rb

Overview

The main Rapid application

This will usually be launched from bin/Rapid.

Instance Method Summary collapse

Constructor Details

#initialize(root, reactor = nil) ⇒ App

Initialises the Rapid application

Parameters:

  • root (Rapid::Services::Root)

    The root module.

  • reactor (Object) (defaults to: nil)

    An object or class that may be used as an asynchronous IO reactor.


19
20
21
22
# File 'lib/ury_rapid/app.rb', line 19

def initialize(root, reactor = nil)
  @root    = root
  @reactor = reactor || EventMachine
end

Instance Method Details

#close(signal) ⇒ Object


34
35
36
37
# File 'lib/ury_rapid/app.rb', line 34

def close(signal)
  $stderr.puts("Caught signal #{signal} -- exiting.")
  EventMachine.stop
end

#runObject

Runs the Rapid application in a new EventMachine instance


25
26
27
28
29
30
31
32
# File 'lib/ury_rapid/app.rb', line 25

def run
  @reactor.run do
    @root.run

    Signal.trap('INT', &method(:close))
    Signal.trap('TERM', &method(:close))
  end
end