Class: Split::Persistence::CookieAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/split/persistence/cookie_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ CookieAdapter

Returns a new instance of CookieAdapter.



9
10
11
12
13
14
# File 'lib/split/persistence/cookie_adapter.rb', line 9

def initialize(context)
  @context = context
  @request, @response = context.request, context.response
  @cookies = @request.cookies
  @expires = Time.now + cookie_length_config
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/split/persistence/cookie_adapter.rb', line 16

def [](key)
  hash[key.to_s]
end

#[]=(key, value) ⇒ Object



20
21
22
# File 'lib/split/persistence/cookie_adapter.rb', line 20

def []=(key, value)
  set_cookie(hash.merge!(key.to_s => value))
end

#delete(key) ⇒ Object



24
25
26
# File 'lib/split/persistence/cookie_adapter.rb', line 24

def delete(key)
  set_cookie(hash.tap { |h| h.delete(key.to_s) })
end

#keysObject



28
29
30
# File 'lib/split/persistence/cookie_adapter.rb', line 28

def keys
  hash.keys
end