Module: CookieAlert

Defined in:
lib/cookie_alert.rb,
lib/cookie_alert/engine.rb,
lib/cookie_alert/version.rb,
app/helpers/cookie_alert/application_helper.rb,
app/helpers/cookie_alert/cookie_alert_helper.rb,
lib/generators/cookie_alert/install_generator.rb,
app/controllers/cookie_alert/cookies_controller.rb,
lib/generators/cookie_alert/uninstall_generator.rb,
app/controllers/cookie_alert/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, CookieAlertHelper, Generators Classes: ApplicationController, Configuration, CookiesController, Engine

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject

Returns the configuration settings for CookieAlert



27
28
29
# File 'lib/cookie_alert.rb', line 27

def self.config
  @config
end

.configure {|@config ||= CookieAlert::Configuration.new| ... } ⇒ Object

Creates or updates the configuration settings for CookieAlert

Parameters:

  • &block (Initialiser Confirguration Block)

    block containing configuration settings for the module’s Configuration object

Yields:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cookie_alert.rb', line 7

def self.configure(&block)
  yield @config ||= CookieAlert::Configuration.new

  # Validate the configuration
  config.cookie_type                          = 'session'   unless ['session','fixed_duration','permanent'].include? config.cookie_type
  
  config.user_must_accept_cookie_use          = true        unless [true,false].include? config.user_must_accept_cookie_use
  config.use_secondary_alert = true        unless [true,false].include? config.use_secondary_alert
  
  config.max_alert_display_count              = 5           unless config.max_alert_display_count.present?       and  config.max_alert_display_count       > 2
  config.num_days_until_cookie_expires        = 60          unless config.num_days_until_cookie_expires.present? and  config.num_days_until_cookie_expires > 1
  
  config.cookie_name                    = config.cookie_name                     || '_we_use_cookies'
  config.cookie_value_text_separator    = config.cookie_value_text_separator     || "~~" 
  config.primary_alert_template         = config.primary_alert_template          || 'cookie_alert/cookies/primary_alert'
  config.secondary_alert_template       = config.secondary_alert_template        || 'cookie_alert/cookies/secondary_alert'
  config.js_acceptance_template         = config.js_acceptance_template          || 'cookie_alert/cookies/cookie_accepted'
end

Instance Method Details

Primary helper method that decides which, if any, of the Alert templates should be rendered



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cookie_alert.rb', line 64

def display_cookie_alert
  # If the visitor has not seen the warning before
  # set a cookie recording the first view
  unless cookies.signed[CookieAlert.config.cookie_name.to_sym]
  
    cookie_alert_set_display_count_cookie 1
    cookie_alert_render_primary_alert

  else
  
    # If the warning has previously been accepted because the visitor has either clicked on the 'accept' link
    # or it has been displayed the required number of times
    if cookies.signed[CookieAlert.config.cookie_name.to_sym] == 'accepted'
    
      # Don't display the notice
      cookie_alert_render_nothing
    
    else
      
      # Retrieve the number of times the Alert has been displayed from the Cookie
      num_views = cookie_alert_get_view_count
        
      # MUST the Visitor accept the Cookie by clicking the link?
      unless CookieAlert.config.user_must_accept_cookie_use
        
        # is this past the max number of Warnings to display? 
        if num_views == CookieAlert.config.max_alert_display_count

          # The visitor has accepted through usage, so set the Cookie to 'accepted'
          cookie_alert_set_accepted_cookie

          # Don't display the notive
          cookie_alert_render_nothing
        
        else

          # Increment the view count & display the warning
          cookie_alert_set_display_count_cookie num_views + 1
          cookie_alert_render_primary_alert

        end

      else

        # The user MUST accept the cookie use and hasn't done so yet
        # Do we display the Full Alert of the Reminder?
        if CookieAlert.config.use_secondary_alert == true and num_views >= CookieAlert.config.max_alert_display_count

          # Display the reminder
          cookie_alert_render_secondary_alert
        
        else

          # Display the full alert
          cookie_alert_set_display_count_cookie num_views + 1
          cookie_alert_render_primary_alert

        end
      end
    end
  end
end