Class: RubyRest::Engine
- Inherits:
-
Object
- Object
- RubyRest::Engine
- Defined in:
- lib/rubyrest/engine.rb
Overview
The Ruby-on-Rest Engine is the glue between the custom application and the webserver implementation
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
The application.
Instance Method Summary collapse
-
#initialize(config) ⇒ Engine
constructor
Initializes the Ruby-on-Rest Engine, Application and Webserver.
-
#intern_config(hash) ⇒ Object
Returns a new hash, with all the keys as symbols.
-
#require_library(params) ⇒ Object
Requires the library params.
-
#start ⇒ Object
Starts the server, embedded or as a detached daemon.
-
#stop ⇒ Object
Shutdowns the current server.
-
#to_s ⇒ Object
Returns the deployed application name.
Constructor Details
#initialize(config) ⇒ Engine
Initializes the Ruby-on-Rest Engine, Application and Webserver. The Application must be installed as a rubygem so that the statement require @service works.
13 14 15 16 17 18 19 20 21 |
# File 'lib/rubyrest/engine.rb', line 13 def initialize( config ) params = intern_config( config ) require_library( params ) @app = Class.by_name( params[:module].capitalize + "::" + params[:service].capitalize + "::Application" ).new( params ) if params[:daemon ] != nil @daemon = params[:daemon ] else @daemon=true end @server = Class.by_name( "RubyRest::" + params[:webserver].to_s.capitalize + "::Server" ).new( @app ) end |
Instance Attribute Details
#app ⇒ Object (readonly)
The application
8 9 10 |
# File 'lib/rubyrest/engine.rb', line 8 def app @app end |
Instance Method Details
#intern_config(hash) ⇒ Object
Returns a new hash, with all the keys as symbols
29 30 31 32 33 |
# File 'lib/rubyrest/engine.rb', line 29 def intern_config( hash ) interned = Hash.new hash.each{ |k,v| interned[ k.intern ] = v } return interned end |
#require_library(params) ⇒ Object
Requires the library params
24 25 26 |
# File 'lib/rubyrest/engine.rb', line 24 def require_library( params ) require params[:gem] if params[:gem] end |
#start ⇒ Object
Starts the server, embedded or as a detached daemon
37 38 39 40 41 42 43 44 |
# File 'lib/rubyrest/engine.rb', line 37 def start if @daemon @pid = fork do @server.up end puts "#{self.to_s}: started - pid=#{@pid}, port=#{@app.config[:http_port]}" else @server.up end end |
#stop ⇒ Object
Shutdowns the current server. This is only useful when working in daemon mode.
48 49 50 51 52 |
# File 'lib/rubyrest/engine.rb', line 48 def stop return if @pid == nil Process.kill( 9, @pid ) puts "#{self.to_s}: killed process with pid=#{@pid}" end |
#to_s ⇒ Object
Returns the deployed application name
55 56 57 |
# File 'lib/rubyrest/engine.rb', line 55 def to_s "rubyrest: #{@app}" end |