Sha256: cc53ce686e36935292883f950a9415ce59277ed52037e1d96a3bb00488ba5226

Contents?: true

Size: 1.56 KB

Versions: 10

Compression:

Stored size: 1.56 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
    class ComponentSessionProxy < Hash #:nodoc:
      def initialize(component_id)
        @component_id = component_id
        super
      end

      def [](key)
        (Netzke::Core.session[@component_id] || {})[key]
      end

      def []=(key, value)
        (Netzke::Core.session[@component_id] ||= {})[key] = value
        # super
      end

      def clear
        Netzke::Core.session[@component_id].clear if Netzke::Core.session[@component_id]
      end
    end

    # Top-level session (straight from the controller).
    def session
      ::Netzke::Core.session
    end

    # Component-specific session.
    def component_session
      @component_session_proxy ||= ComponentSessionProxy.new(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.deep_merge!(:options => 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

10 entries across 10 versions & 1 rubygems

Version Path
netzke-core-0.7.7 lib/netzke/session.rb
netzke-core-0.7.6 lib/netzke/session.rb
netzke-core-0.7.5 lib/netzke/session.rb
netzke-core-0.7.4 lib/netzke/session.rb
netzke-core-0.7.3 lib/netzke/session.rb
netzke-core-0.7.2 lib/netzke/session.rb
netzke-core-0.7.1 lib/netzke/session.rb
netzke-core-0.6.7 lib/netzke/session.rb
netzke-core-0.7.0 lib/netzke/session.rb
netzke-core-0.6.6 lib/netzke/session.rb