Module: Evercookie::ControllerHelpers

Defined in:
lib/evercookie/controller.rb

Overview

defines controller helpers

Instance Method Summary collapse

Instance Method Details

#evercookie_get_value(key) ⇒ Object

Get value of evercookie by key

Examples:

evercookie_get_value(:key)

9
10
11
12
13
14
15
# File 'lib/evercookie/controller.rb', line 9

def evercookie_get_value(key)
  if session[Evercookie.hash_name_for_saved].present?
    session[Evercookie.hash_name_for_saved][key]
  else
    nil
  end
end

#evercookie_is_set?(key, value = nil) ⇒ Boolean

Checks whether the evercookie with specific key was defined

Examples:

evercookie_is_set?(:key)
evercookie_is_set?(:key, :value)

32
33
34
35
36
37
38
39
40
41
# File 'lib/evercookie/controller.rb', line 32

def evercookie_is_set?(key, value = nil)
  if session[Evercookie.hash_name_for_saved].blank?
    false
  elsif value.nil?
    session[Evercookie.hash_name_for_saved][key].present?
  else
    session[Evercookie.hash_name_for_saved][key].present? \
      && session[Evercookie.hash_name_for_saved][key] == value
  end
end

#set_evercookie(key, value) ⇒ Object

Set evercookie value to session

Examples:

set_evercookie(:key, :value)

21
22
23
24
25
# File 'lib/evercookie/controller.rb', line 21

def set_evercookie(key, value)
  session[Evercookie.hash_name_for_saved] = {} unless
    session[Evercookie.hash_name_for_saved].present?
  session[Evercookie.hash_name_for_saved][key] = value
end