Sha256: 36bdb7b26fea0bdd6c74f5157aded2152f37d72807ecbed459270983031fda11

Contents?: true

Size: 934 Bytes

Versions: 2

Compression:

Stored size: 934 Bytes

Contents

module HasGlobalSession
  class IntegratedSession
    def initialize(local_session, global_session)
      @local_session = local_session
      @global_session = global_session
    end

    def [](key)
      key = key.to_s
      if @global_session.supports_key?(key)
        @global_session[key]
      else
        @local_session[key]
      end
    end

    def []=(key, value)
      key = key.to_s
      if @global_session.supports_key?(key)
        @global_session[key] = value
      else
        @local_session[key] = value
      end
    end

    def has_key?(key)
      key = key.to_s
      @global_session.has_key(key) || @local_session.has_key?(key)
    end

    def keys
      @global_session.keys + @local_session.keys
    end

    def values
      @global_session.values + @local_session.values
    end

    def each_pair(&block)
      @global_session.each_pair(&block)
      @local_session.each_pair(&block)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
has_global_session-0.8.2 lib/has_global_session/integrated_session.rb
has_global_session-0.8.1 lib/has_global_session/integrated_session.rb