Class: Citrus::Common::Service::SessionService::FrontendSession
- Inherits:
-
Object
- Object
- Citrus::Common::Service::SessionService::FrontendSession
- Includes:
- Utils::EventEmitter
- Defined in:
- lib/citrus/common/service/session_service.rb
Overview
FrontendSession
Instance Method Summary collapse
-
#bind(uid, &block) ⇒ Object
Bind the frontend session with the uid.
-
#export ⇒ Object
Export the key/values for serialization.
-
#get(key) ⇒ Object
Get value from the frontend session.
-
#initialize(session) ⇒ FrontendSession
constructor
Create a new frontend session.
-
#push(key, &block) ⇒ Object
Push value to the internal session.
-
#push_all(&block) ⇒ Object
Push all the key/value pairs to the internal session.
-
#set(key, value) ⇒ Object
Set value for the frontend session.
-
#unbind(uid, &block) ⇒ Object
Unbind the session with the uid.
Methods included from Utils::EventEmitter
Constructor Details
#initialize(session) ⇒ FrontendSession
Create a new frontend session
374 375 376 377 378 379 380 381 |
# File 'lib/citrus/common/service/session_service.rb', line 374 def initialize session FRONTEND_SESSION_FIELDS.each { |field| instance_eval %Q{ @#{field} = session.#{field} } } # deep copy for settings @settings = session.settings.dup @session = session end |
Instance Method Details
#bind(uid, &block) ⇒ Object
Bind the frontend session with the uid
386 387 388 389 390 391 392 393 |
# File 'lib/citrus/common/service/session_service.rb', line 386 def bind uid, &block @session_service.bind(@id, uid) { |err| unless err @uid = uid end block_given? and yield err } end |
#export ⇒ Object
Export the key/values for serialization
435 436 437 438 439 440 441 |
# File 'lib/citrus/common/service/session_service.rb', line 435 def export res = {} EXPORTED_SESSION_FIELDS.each { |field| instance_eval %Q{ res['#{field}'] = @#{field} } } res end |
#get(key) ⇒ Object
Get value from the frontend session
418 419 420 |
# File 'lib/citrus/common/service/session_service.rb', line 418 def get key @settings[key] end |
#push(key, &block) ⇒ Object
Push value to the internal session
425 426 427 |
# File 'lib/citrus/common/service/session_service.rb', line 425 def push key, &block @session_service.import @id, key, get(key), &block end |
#push_all(&block) ⇒ Object
Push all the key/value pairs to the internal session
430 431 432 |
# File 'lib/citrus/common/service/session_service.rb', line 430 def push_all &block @session_service.import_all @id, @settings, &block end |
#set(key, value) ⇒ Object
Set value for the frontend session
411 412 413 |
# File 'lib/citrus/common/service/session_service.rb', line 411 def set key, value @settings[key] = value end |
#unbind(uid, &block) ⇒ Object
Unbind the session with the uid
398 399 400 401 402 403 404 405 |
# File 'lib/citrus/common/service/session_service.rb', line 398 def unbind uid, &block @session_service.unbind(@id, uid) { |err| unless err @uid = nil end block_given? and yield err } end |