class Citrus::Common::Service::SessionService::FrontendSession

FrontendSession

Public Class Methods

new(session) click to toggle source

Create a new frontend session

@param [Object] session

# 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

Public Instance Methods

bind(uid) { |err| ... } click to toggle source

Bind the frontend session with the uid

@param [String] uid

# 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() click to toggle source

Export the key/values for serialization

# 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) click to toggle source

Get value from the frontend session

@param [String] key

# File lib/citrus/common/service/session_service.rb, line 418
def get key
  @settings[key]
end
push(key, &block) click to toggle source

Push value to the internal session

@param [String] key

# 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) click to toggle source

Push all the key/value pairs to the internal session

# 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) click to toggle source

Set value for the frontend session

@param [String] key @param [Hash] value

# File lib/citrus/common/service/session_service.rb, line 411
def set key, value
  @settings[key] = value
end
unbind(uid) { |err| ... } click to toggle source

Unbind the session with the uid

@param [String] uid

# 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