Class: Flip::CookieStrategy

Inherits:
AbstractStrategy show all
Defined in:
lib/flip/cookie_strategy.rb

Defined Under Namespace

Modules: Loader

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractStrategy

#name

Class Method Details

.cookies=(cookies) ⇒ Object



29
30
31
# File 'lib/flip/cookie_strategy.rb', line 29

def self.cookies= cookies
  @cookies = cookies
end

Instance Method Details



33
34
35
36
# File 'lib/flip/cookie_strategy.rb', line 33

def cookie_name(definition)
  definition = definition.key unless definition.is_a? Symbol
  "flip_#{definition}"
end

#delete!(key) ⇒ Object



25
26
27
# File 'lib/flip/cookie_strategy.rb', line 25

def delete! key
  cookies.delete cookie_name(key)
end

#descriptionObject



5
6
7
# File 'lib/flip/cookie_strategy.rb', line 5

def description
  "Uses cookies to apply only to your session."
end

#knows?(definition) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/flip/cookie_strategy.rb', line 9

def knows? definition
  cookies.key? cookie_name(definition)
end

#on?(definition) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/flip/cookie_strategy.rb', line 13

def on? definition
  cookies[cookie_name(definition)] === "true"
end

#switch!(key, on) ⇒ Object



21
22
23
# File 'lib/flip/cookie_strategy.rb', line 21

def switch! key, on
  cookies[cookie_name(key)] = on ? "true" : "false"
end

#switchable?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/flip/cookie_strategy.rb', line 17

def switchable?
  true
end