Class: Shimmer::ConsentSettings
- Inherits:
-
Object
- Object
- Shimmer::ConsentSettings
- Defined in:
- lib/shimmer/utils/consent_settings.rb
Constant Summary collapse
- SETTINGS =
[:essential, :targeting, :statistic].freeze
- DEFAULT =
[:essential].freeze
Instance Method Summary collapse
- #given? ⇒ Boolean
-
#initialize(cookies) ⇒ ConsentSettings
constructor
A new instance of ConsentSettings.
- #save ⇒ Object
Constructor Details
#initialize(cookies) ⇒ ConsentSettings
Returns a new instance of ConsentSettings.
13 14 15 16 17 18 19 |
# File 'lib/shimmer/utils/consent_settings.rb', line 13 def initialize() @cookies = allowed = @cookies[:consent].to_s.split(",").map(&:strip) SETTINGS.each do |setting| instance_variable_set "@#{setting}", DEFAULT.include?(setting) || allowed.include?(setting.to_s) end end |
Instance Method Details
#given? ⇒ Boolean
26 27 28 |
# File 'lib/shimmer/utils/consent_settings.rb', line 26 def given? @cookies[:consent].present? end |
#save ⇒ Object
21 22 23 24 |
# File 'lib/shimmer/utils/consent_settings.rb', line 21 def save value = SETTINGS.map { |e| e.to_s if instance_variable_get("@#{e}") }.compact.join(",") @cookies.permanent[:consent] = {value: value, expires: 2.years.from_now} end |