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



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

def self.cookies= cookies
  @cookies = cookies
end

Instance Method Details



38
39
40
41
# File 'lib/flip/cookie_strategy.rb', line 38

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

#delete!(key) ⇒ Object



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

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
16
17
# File 'lib/flip/cookie_strategy.rb', line 13

def on? definition
  cookie = cookies[cookie_name(definition)]
  cookie_value = cookie.is_a?(Hash) ? cookie['value'] : cookie
  cookie_value === 'true'
end

#switch!(key, on) ⇒ Object



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

def switch! key, on
  cookies[cookie_name(key)] = {
    'value' => (on ? "true" : "false"),
    'domain' => :all
  }
end

#switchable?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/flip/cookie_strategy.rb', line 19

def switchable?
  true
end