Class: Flipflop::Strategies::CookieStrategy
Instance Attribute Summary
#description, #key, #name, #title
Class Method Summary
collapse
Instance Method Summary
collapse
default_name, #hidden?, #reset!
Constructor Details
Returns a new instance of CookieStrategy.
10
11
12
13
14
15
|
# File 'lib/flipflop/strategies/cookie_strategy.rb', line 10
def initialize(**options)
@options = options.(:path, :domain, :secure, :httponly).freeze
@prefix = options.delete(:prefix).to_s.freeze
super(**options)
end
|
Class Method Details
.default_description ⇒ Object
5
6
7
|
# File 'lib/flipflop/strategies/cookie_strategy.rb', line 5
def default_description
"Stores features in a browser cookie. Applies to current user."
end
|
Instance Method Details
#clear!(feature) ⇒ Object
34
35
36
|
# File 'lib/flipflop/strategies/cookie_strategy.rb', line 34
def clear!(feature)
request.cookie_jar.delete(cookie_key(feature), **@options)
end
|
#enabled?(feature) ⇒ Boolean
21
22
23
24
25
26
27
|
# File 'lib/flipflop/strategies/cookie_strategy.rb', line 21
def enabled?(feature)
return unless request?
return unless request.cookie_jar.has_key?(cookie_key(feature))
cookie = request.cookie_jar[cookie_key(feature)]
cookie_value = cookie.is_a?(Hash) ? cookie["value"] : cookie
cookie_value === "1"
end
|
#switch!(feature, enabled) ⇒ Object
29
30
31
32
|
# File 'lib/flipflop/strategies/cookie_strategy.rb', line 29
def switch!(feature, enabled)
value = @options.merge(value: enabled ? "1" : "0")
request.cookie_jar[cookie_key(feature)] = value
end
|
#switchable? ⇒ Boolean
17
18
19
|
# File 'lib/flipflop/strategies/cookie_strategy.rb', line 17
def switchable?
request?
end
|