Sha256: e6c3ff60a0e1d9bc48206288c0c2e4197a99dc84c63effff89cd3f7d2108dede

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Cmor
  module Legal
    class CookieStore
      attr_accessor :cookies

      def initialize(store)
        @store = store
      end

      def self.cookie_prefix
        ::Cmor::Legal::Configuration.cookie_prefix
      end

      def self.add_prefix_to_identifier(identifier)
        "#{cookie_prefix}#{identifier}"
      end

      def get_value(identifier)
        @store[self.class.add_prefix_to_identifier(identifier)]
      end

      def set_value(identifier, value, expires = nil)
        if @store.is_a?(ActionDispatch::Cookies::CookieJar)
          @store[self.class.add_prefix_to_identifier(identifier)] = { value: value, expires: expires }
        else
          @store[self.class.add_prefix_to_identifier(identifier)] = value
        end
      end

      def cookies
        @store.select { |key, value| key.to_s.start_with?(self.class.cookie_prefix) }.each_with_object({}) do |(k, v), m|
          m[k.gsub(self.class.cookie_prefix, "")] = v
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cmor_legal-0.0.60.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.59.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.58.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.57.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.56.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.55.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.54.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.53.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.52.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.51.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.50.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.49.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.48.pre app/models/cmor/legal/cookie_store.rb
cmor_legal-0.0.45.pre app/models/cmor/legal/cookie_store.rb