Class: RSence::Plugins::Servlet__
- Inherits:
-
Object
- Object
- RSence::Plugins::Servlet__
- Includes:
- PluginBase
- Defined in:
- lib/rsence/plugins/servlet.rb
Overview
Use the Servlet class to create responders for GET / POST urls.
A Servlet’s public API is accessible like the other plugins directly.
Responding to a URL consists of four phases:
-
PluginManager calls every #match method
-
The plugins that return true to the #match method are queried by their score -method
-
The matched plugins are sorted by score, lowest score wins. If it’s a draw between equal scores, the choice is randomized.
-
The #post or #get method is called, depending on the type of HTTP request.
Extension hooks for server events
These methods are provided as the basic server event hooks:
-
#init
– Use instead ofinitialize
-
#open
– Extend to open objects -
#flush
– Extend to write the state and to flush buffers -
#close
– Extend to close objects
Extension hooks for REST events
Instance Attribute Summary collapse
-
#info ⇒ Hash
readonly
The meta-information of the plugin bundle.
-
#name ⇒ Symbol
readonly
The name of the plugin bundle.
-
#path ⇒ String
readonly
The absolute path of the plugin bundle.
Instance Method Summary collapse
-
#get(req, res, ses) ⇒ Object
Extend to do any GET request processing.
-
#match(uri, request_type = :get) ⇒ true, false
(also: #match?)
Extend to return true for the certain uri and request_type conditions your servlet code handles.
-
#post(req, res, ses) ⇒ Object
Extend to do any POST request processing.
-
#score ⇒ Number
If matched, returns score where lower is better.
Methods included from PluginBase
#bundle_path, #close, #file_exist?, #file_read, #file_write, #flush, #httime, #init, #json_read, #method_missing, #open, #yaml_read, #yaml_write
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSence::Plugins::PluginBase
Instance Attribute Details
#info ⇒ Hash (readonly)
Returns The meta-information of the plugin bundle.
52 53 54 |
# File 'lib/rsence/plugins/servlet.rb', line 52 def info @info end |
#name ⇒ Symbol (readonly)
Returns The name of the plugin bundle.
46 47 48 |
# File 'lib/rsence/plugins/servlet.rb', line 46 def name @name end |
#path ⇒ String (readonly)
Returns The absolute path of the plugin bundle.
49 50 51 |
# File 'lib/rsence/plugins/servlet.rb', line 49 def path @path end |
Instance Method Details
#get(req, res, ses) ⇒ Object
Extend to do any GET request processing. Not doing anything by default.
89 |
# File 'lib/rsence/plugins/servlet.rb', line 89 def get( req, res, ses ); end |
#match(uri, request_type = :get) ⇒ true, false Also known as: match?
Extend to return true for the certain uri and request_type conditions your servlet code handles.
76 |
# File 'lib/rsence/plugins/servlet.rb', line 76 def match( uri, request_type=:get ); false; end |
#post(req, res, ses) ⇒ Object
Extend to do any POST request processing. Not doing anything by default.
96 |
# File 'lib/rsence/plugins/servlet.rb', line 96 def post( req, res, ses ); end |
#score ⇒ Number
If matched, returns score where lower is better. Score is needed for priority sorting, when several Servlet’s #match are returning true for the same request.
82 |
# File 'lib/rsence/plugins/servlet.rb', line 82 def score; 100; end |