Class: SnowplowRubyDuid::Cookie
- Inherits:
-
Object
- Object
- SnowplowRubyDuid::Cookie
- Defined in:
- lib/snowplow_ruby_duid/cookie.rb
Overview
Responsible for generating a cookie that emulates the Snowplow cookie as closely as possible Leverages the method used by ActionDispatch::Cookies::CookieJar to determine the top-level domain
Constant Summary collapse
- COOKIE_PATH =
'/'
- COOKIE_DURATION_MONTHS =
24
- DOMAIN_REGEXP =
/[^.]*\.([^.]*|..\...|...\...)$/.freeze
Instance Method Summary collapse
-
#initialize(host, domain_userid, request_created_at, options = {}) ⇒ Cookie
constructor
A new instance of Cookie.
- #key ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(host, domain_userid, request_created_at, options = {}) ⇒ Cookie
Returns a new instance of Cookie.
14 15 16 17 18 19 20 |
# File 'lib/snowplow_ruby_duid/cookie.rb', line 14 def initialize(host, domain_userid, request_created_at, = {}) @host = host @domain_userid = domain_userid @request_created_at = request_created_at @secure = .fetch(:secure) @same_site = .fetch(:same_site) end |
Instance Method Details
#key ⇒ Object
24 25 26 27 |
# File 'lib/snowplow_ruby_duid/cookie.rb', line 24 def key domain = top_level_domain || @host KEY_PREFIX + '.' + Digest::SHA1.hexdigest(domain + COOKIE_PATH)[0..3] end |
#value ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/snowplow_ruby_duid/cookie.rb', line 29 def value = ".#{top_level_domain}" unless top_level_domain.nil? base = { value: , expires: , domain: , path: COOKIE_PATH, same_site: @same_site } base.merge!(secure: true) if @secure base end |