Sha256: 715be4659cf61d35e88e2bd068e3bf089fc4ece1093a956c3108afa1e18d745a

Contents?: true

Size: 886 Bytes

Versions: 2

Compression:

Stored size: 886 Bytes

Contents

module Sojourn
  module SessionStores
    class Cookie
      def initialize(ctx)
        @ctx = ctx
      end

      def sojourner_uuid
        cookie_data[:uuid]
      end

      def sojourner_uuid=(value)
        cookies.permanent.signed[cookie_name] = { value: cookie_data.merge(uuid: value) }
      end

      def sojourner_tracked?
        cookie_data.key?(:uuid)
      end

      def user_id
        cookie_data[:user_id]
      end

      def user_id=(value)
        cookies.permanent.signed[cookie_name] = { value: cookie_data.merge(user_id: value) }
      end

      def user_tracked?
        cookie_data.key?(:user_id)
      end

    private

      def cookie_data
        cookies.signed[cookie_name] || {}
      end

      def cookies
        @ctx.send(:cookies)
      end

      def cookie_name
        @cookie_name ||= Sojourn.config.cookie_name
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sojourn-0.1.1 lib/sojourn/session_stores/cookie.rb
sojourn-0.1.0 lib/sojourn/session_stores/cookie.rb