Class: RSence::Message
- Inherits:
-
Object
- Object
- RSence::Message
- Defined in:
- lib/rsence/msg.rb
Overview
A Message instance is used as a ‘messenger class` while processing client-server requests. It’s initialized by the system and the convention guideline for its instance is msg, pass it on wherever msg might be needed. In most cases, the use of msg is to just pass the same msg onward from a method to another.
Instance Attribute Summary collapse
-
#cloned_source ⇒ false, Hash
Contains the source ses on the first request after the active session was cloned from another session.
-
#cloned_targets ⇒ false, Array<Hash>
Contains the target sessions packed in an Array on the first request after another session was cloned from the active session.
-
#new_session ⇒ Boolean
Flag for a new session’s first request.
-
#plugins ⇒ PluginManager
Reference to the main PluginManager.
-
#request ⇒ Request
The HTTP Request object of the active request.
-
#response ⇒ Response
The HTTP Response object of the active request.
-
#restored_session ⇒ Boolean
Flag for a restored session’s first request.
-
#sessions ⇒ SessionManager
Reference to SessionManager.
-
#transporter ⇒ Transporter
Reference to Transporter.
-
#valuemanager ⇒ ValueManager
Reference to ValueManager.
Instance Method Summary collapse
-
#call(plugin_name, plugin_method, *args) ⇒ Object
(also: #run)
Calls a method of a registered plugin with optional arguments.
-
#coffee(data) ⇒ Object
Same as #reply, but with CoffeeScript instead of JS.
-
#console(data) ⇒ Object
(also: #puts)
Sends data to the client’s javascript console.
-
#expire_session ⇒ nil
Invalidates the active session.
- #inspect ⇒ Object
- #release_rsrc(uri) ⇒ Object (also: #unserve_rsrc) deprecated Deprecated.
-
#reply(data, dont_squeeze = false) ⇒ Object
Sends data to the client, usually javascript, but is valid for any data that responds to #to_json.
- #serve_file(file_data, content_type = 'text/plain', filename = 'untitled.txt') ⇒ String deprecated Deprecated.
- #serve_img(img_obj, img_format = 'PNG') ⇒ String deprecated Deprecated.
- #serve_rsrc(rsrc_data, content_type = 'text/plain') ⇒ String deprecated Deprecated.
-
#ses_id ⇒ Number
(also: #session_id)
Returns the session id.
-
#user_id ⇒ Number, String
Getter for the user id.
-
#user_id=(user_id) ⇒ nil
Setter for the user id.
-
#user_info ⇒ Hash
Getter for the user info hash.
-
#user_info=(user_info) ⇒ nil
Setter for the user info.
Instance Attribute Details
#cloned_source ⇒ false, Hash
Contains the source ses on the first request after the active session was cloned from another session.
58 59 60 |
# File 'lib/rsence/msg.rb', line 58 def cloned_source @cloned_source end |
#cloned_targets ⇒ false, Array<Hash>
Contains the target sessions packed in an Array on the first request after another session was cloned from the active session.
62 63 64 |
# File 'lib/rsence/msg.rb', line 62 def cloned_targets @cloned_targets end |
#new_session ⇒ Boolean
Flag for a new session’s first request. Check it in your code to decide what to do, when a new session is encountered. In systems that require authentication, this may be used as a trigger to display a login/register dialog.
49 50 51 |
# File 'lib/rsence/msg.rb', line 49 def new_session @new_session end |
#plugins ⇒ PluginManager
Reference to the main PluginManager
98 99 100 |
# File 'lib/rsence/msg.rb', line 98 def plugins @plugins end |
#request ⇒ Request
The HTTP Request object of the active request.
69 70 71 |
# File 'lib/rsence/msg.rb', line 69 def request @request end |
#response ⇒ Response
The HTTP Response object of the active request.
73 74 75 |
# File 'lib/rsence/msg.rb', line 73 def response @response end |
#restored_session ⇒ Boolean
Flag for a restored session’s first request. Check it in your code to decide what to do, when a restored session is encountered.
54 55 56 |
# File 'lib/rsence/msg.rb', line 54 def restored_session @restored_session end |
#sessions ⇒ SessionManager
Reference to SessionManager
94 95 96 |
# File 'lib/rsence/msg.rb', line 94 def sessions @sessions end |
#transporter ⇒ Transporter
Reference to Transporter
86 87 88 |
# File 'lib/rsence/msg.rb', line 86 def transporter @transporter end |
#valuemanager ⇒ ValueManager
Reference to ValueManager
90 91 92 |
# File 'lib/rsence/msg.rb', line 90 def valuemanager @valuemanager end |
Instance Method Details
#call(plugin_name, plugin_method, *args) ⇒ Object Also known as: run
Calls a method of a registered plugin with optional arguments.
369 370 371 |
# File 'lib/rsence/msg.rb', line 369 def call( plugin_name, plugin_method, *args ) @plugins.call( plugin_name, plugin_method, *args) end |
#coffee(data) ⇒ Object
Same as #reply, but with CoffeeScript instead of JS
292 293 294 295 |
# File 'lib/rsence/msg.rb', line 292 def coffee(data) puts data if @config[:trace] @buffer.push( @plugins[:client_pkg].coffee( data ) ) end |
#console(data) ⇒ Object Also known as: puts
Sends data to the client’s javascript console.
312 313 314 |
# File 'lib/rsence/msg.rb', line 312 def console(data) reply( "console.log(#{data.to_json});" ) end |
#expire_session ⇒ nil
Invalidates the active session.
161 162 163 |
# File 'lib/rsence/msg.rb', line 161 def expire_session @sessions.expire_session( @session[:ses_id] ) if @session end |
#inspect ⇒ Object
374 375 376 |
# File 'lib/rsence/msg.rb', line 374 def inspect "#<Message ses_id:#{ses_id.inspect}, ses_key: #{ses_key.inspect} ...>" end |
#release_rsrc(uri) ⇒ Object Also known as: unserve_rsrc
Removes the URL served, you must call this manually when after a served resource is no longer needed! Calls the default ‘ticket` plugin. Use ticket.serve_rsrc directly instead.
360 361 362 |
# File 'lib/rsence/msg.rb', line 360 def release_rsrc( uri ) call(:ticket,:del_rsrc, uri[3..-1] ) end |
#reply(data, dont_squeeze = false) ⇒ Object
Sends data to the client, usually javascript, but is valid for any data that responds to #to_json
284 285 286 287 288 289 |
# File 'lib/rsence/msg.rb', line 284 def reply(data,dont_squeeze=false) data.strip! data = @plugins[:client_pkg].squeeze( data ) unless dont_squeeze puts data if @config[:trace] @buffer.push( data ) end |
#serve_file(file_data, content_type = 'text/plain', filename = 'untitled.txt') ⇒ String
Binary data to be served once as a downloadable file attachment, returns a disposable URL. Calls the default ‘ticket` plugin. Use ticket.serve_file directly instead.
336 337 338 |
# File 'lib/rsence/msg.rb', line 336 def serve_file( file_data, content_type='text/plain', filename='untitled.txt' ) call( :ticket, :serve_file, self, file_data, content_type, filename ) end |
#serve_img(img_obj, img_format = 'PNG') ⇒ String
Serves an image object and returns its disposable URL. Calls the default ‘ticket` plugin. Use ticket.serve_img directly instead.
324 325 326 |
# File 'lib/rsence/msg.rb', line 324 def serve_img( img_obj, img_format='PNG' ) call( :ticket, :serve_img, self, img_obj, img_format ) end |
#serve_rsrc(rsrc_data, content_type = 'text/plain') ⇒ String
Sends any binary to be served indefinitely, returns a unique, random, static URL. Calls the default ‘ticket` plugin. IMPORTANT: PLEASE call #release_rsrc manually, when the resource is no longer needed to free the memory occupied! HINT: In most cases, it’s a better idea to use serve_img or serve_file to expire the resource automatically. Use ticket.serve_rsrc directly instead.
350 351 352 |
# File 'lib/rsence/msg.rb', line 350 def serve_rsrc( rsrc_data, content_type='text/plain' ) call(:ticket,:serve_rsrc,self, rsrc_data, content_type ) end |
#ses_id ⇒ Number Also known as: session_id
Returns the session id
215 216 217 |
# File 'lib/rsence/msg.rb', line 215 def ses_id @session[:ses_id] end |
#user_id ⇒ Number, String
Getter for the user id
178 179 180 |
# File 'lib/rsence/msg.rb', line 178 def user_id @session[:user_id] end |
#user_id=(user_id) ⇒ nil
Setter for the user id
202 203 204 |
# File 'lib/rsence/msg.rb', line 202 def user_id=(user_id) @session[:user_id] = user_id end |
#user_info ⇒ Hash
Getter for the user info hash
184 185 186 187 |
# File 'lib/rsence/msg.rb', line 184 def user_info @session[:user_info] = {} unless @session.has_key?(:user_info) @session[:user_info] end |
#user_info=(user_info) ⇒ nil
Setter for the user info
209 210 211 |
# File 'lib/rsence/msg.rb', line 209 def user_info=(user_info) @session[:user_info] = user_info end |