Class: Consently::Providers::Base
- Inherits:
-
Object
- Object
- Consently::Providers::Base
- Defined in:
- lib/consently/providers/base.rb
Overview
A tag vendor: what scripts it needs and which consent category it falls under. Subclasses describe the snippet as data (see Consently::Script) so the view can render it live or blocked from the same description.
Direct Known Subclasses
Clarity, Custom, GoogleAds, GoogleAnalytics, GoogleTagManager, Hotjar, MetaPixel, Plausible
Constant Summary collapse
- SAFE_OPTION =
Ids are interpolated straight into JavaScript, so they are held to a shape that cannot carry a quote or a bracket out of the string.
/\A[\w\-.:\/]+\z/
Class Attribute Summary collapse
-
.default_category ⇒ Object
Set by each subclass; where a vendor is unambiguous (Plausible does not touch cookies) it can say :necessary and load right away.
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .build(key, **options) ⇒ Object
-
.cookie(name, days: nil) ⇒ Object
What this vendor stores in the visitor's browser, for the policy page.
- .cookie_manifest ⇒ Object
- .provider_key ⇒ Object
- .provider_key=(key) ⇒ Object
- .register(key, klass) ⇒ Object
- .registry ⇒ Object
Instance Method Summary collapse
-
#cookies ⇒ Object
ArrayConsently::Cookie - what this tag leaves in the browser.
-
#initialize(**options) ⇒ Base
constructor
A new instance of Base.
-
#noscript ⇒ Object
Rendered inside
, for vendors that still ship a -
#scripts ⇒ Object
ArrayConsently::Script.
- #to_s ⇒ Object
Constructor Details
#initialize(**options) ⇒ Base
Returns a new instance of Base.
51 52 53 54 55 56 |
# File 'lib/consently/providers/base.rb', line 51 def initialize(**) @options = @category = ([:category] || self.class.default_category).to_sym @key = ([:as] || self.class.provider_key).to_sym validate! end |
Class Attribute Details
.default_category ⇒ Object
Set by each subclass; where a vendor is unambiguous (Plausible does not touch cookies) it can say :necessary and load right away.
27 28 29 |
# File 'lib/consently/providers/base.rb', line 27 def default_category @default_category end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
49 50 51 |
# File 'lib/consently/providers/base.rb', line 49 def category @category end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
49 50 51 |
# File 'lib/consently/providers/base.rb', line 49 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
49 50 51 |
# File 'lib/consently/providers/base.rb', line 49 def @options end |
Class Method Details
.build(key, **options) ⇒ Object
20 21 22 23 |
# File 'lib/consently/providers/base.rb', line 20 def build(key, **) klass = registry[key.to_sym] or raise UnknownProvider, key klass.new(**) end |
.cookie(name, days: nil) ⇒ Object
What this vendor stores in the visitor's browser, for the policy
page. days: nil means a session cookie.
40 41 42 |
# File 'lib/consently/providers/base.rb', line 40 def (name, days: nil) << { name: name, days: days } end |
.cookie_manifest ⇒ Object
44 45 46 |
# File 'lib/consently/providers/base.rb', line 44 def @cookie_manifest ||= [] end |
.provider_key ⇒ Object
29 30 31 |
# File 'lib/consently/providers/base.rb', line 29 def provider_key @provider_key end |
.provider_key=(key) ⇒ Object
33 34 35 36 |
# File 'lib/consently/providers/base.rb', line 33 def provider_key=(key) @provider_key = key.to_sym register(@provider_key, self) end |
.register(key, klass) ⇒ Object
16 17 18 |
# File 'lib/consently/providers/base.rb', line 16 def register(key, klass) registry[key.to_sym] = klass end |
.registry ⇒ Object
12 13 14 |
# File 'lib/consently/providers/base.rb', line 12 def registry @@registry ||= {} end |
Instance Method Details
#cookies ⇒ Object
ArrayConsently::Cookie - what this tag leaves in the browser.
64 65 66 |
# File 'lib/consently/providers/base.rb', line 64 def self.class..map { |attributes| Cookie.new(**attributes, provider: key) } end |
#noscript ⇒ Object
Rendered inside
, for vendors that still ship a
70 71 72 |
# File 'lib/consently/providers/base.rb', line 70 def noscript nil end |
#scripts ⇒ Object
ArrayConsently::Script
59 60 61 |
# File 'lib/consently/providers/base.rb', line 59 def scripts [] end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/consently/providers/base.rb', line 74 def to_s "#{key} (#{category})" end |