Sha256: 3687df4b5a585664147cb4b205d409f17a2870d3c475b57b5f25def96a6a67db

Contents?: true

Size: 1.13 KB

Versions: 14

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Cmor
  module Legal
    class CookiePreferences
      include ActiveModel::Model

      attr_accessor :cookies, :cookie_store

      def initialize(*attrs)
        super
        @cookies ||= ::Cmor::Legal::Configuration.cookies.call(cookie_store)
        @cookies.map(&:identifier).each do |identifier|
          singleton_class.class_eval do
            # attr_accessor c
            define_method(identifier) do
              @cookies.find { |c| c.identifier == identifier }.value
            end

            define_method("#{identifier}=") do |value|
              @cookies.find { |c| c.identifier == identifier }.value = value
            end
          end
        end
      end

      def update_attributes(attributes)
        attributes.each do |identifier, value|
          @cookies.find { |c| c.identifier == identifier.to_sym }.value = value
        end
        save
      end

      def save
        @cookies.each { |c| c.save }
      end

      def accepted?(identifier)
        send(identifier)
      end

      def accepted_cookies
        cookies.select { |c| c.accepted? }
      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_preferences.rb
cmor_legal-0.0.59.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.58.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.57.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.56.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.55.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.54.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.53.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.52.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.51.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.50.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.49.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.48.pre app/models/cmor/legal/cookie_preferences.rb
cmor_legal-0.0.45.pre app/models/cmor/legal/cookie_preferences.rb