Sha256: b3fb213f77644b6f494be83144e79843bd6e01ec76ee8b409479fed455cf72ac

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module Netzke
  # This modules provides (component-specific) session manupulation.
  # The :session_persistence config option should be set to true in order for the component to make use of this.
  module Session
    # Top-level session (straight from the controller).
    def session
      ::Netzke::Core.session
    end
  
    # Component-specific session.
    def component_session
      session[global_id] ||= {}
    end
    
    # Returns this component's configuration options stored in the session. Those get merged into the component's configuration at instantiation.
    def session_options
      session_persistence_enabled? && component_session[:options] || {}
    end
 
    # Updates the session options
    def update_session_options(hash)
      if session_persistence_enabled?
        component_session[:options] ||= {}
        component_session[:options].merge!(hash)
      else
        logger.debug "Netzke warning: No session persistence enabled for component '#{global_id}'"
      end
    end
    
    private
      def session_persistence_enabled?
        initial_config[:session_persistence]
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
netzke-core-0.6.2 lib/netzke/session.rb
netzke-core-0.6.1 lib/netzke/session.rb
netzke-core-0.6.0 lib/netzke/session.rb