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
-
.config ⇒ Object
Returns the configuration settings for CookieAlert.
-
.configure {|@config ||= CookieAlert::Configuration.new| ... } ⇒ Object
Creates or updates the configuration settings for CookieAlert @param &block [Initialiser Confirguration Block] block containing configuration settings for the module's Configuration object.
Instance Method Summary collapse
-
#cookie_alert_get_current_url ⇒ Object
private
Gets the visitor's current page URL from the Cookie data.
-
#cookie_alert_get_view_count ⇒ Object
private
Gets the number of views from the Cookie data.
-
#cookie_alert_render_nothing ⇒ Object
private
Renders a blank template for those times when an Alert should not be displayed.
-
#cookie_alert_render_primary_alert ⇒ Object
private
Renders the primary Alert template.
-
#cookie_alert_render_secondary_alert ⇒ Object
private
Renders the secondary Alert remplate.
-
#cookie_alert_set_accepted_cookie ⇒ Object
private
Sets the value of the cookie to "accepted".
-
#cookie_alert_set_cookie(cookie_value = '') ⇒ Object
private
Creates the Cookie, setting the expiry time and the data value @param cookie_value [string] data content of the Cookie.
-
#cookie_alert_set_display_count_cookie(num_views) ⇒ Object
private
Set the data value of the cookie to include the number of views and the current URL @param num_views [integer] the number of time the visitor has viewed an Alert.
-
#display_cookie_alert ⇒ Object
Primary helper method that decides which, if any, of the Alert templates should be rendered.
Class Method Details
.config ⇒ Object
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 @param &block [Initialiser Confirguration Block] block containing configuration settings for the module's Configuration object
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. = 'session' unless ['session','fixed_duration','permanent'].include? config. config. = true unless [true,false].include? config. 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. = 60 unless config..present? and config. > 1 config. = config. || '_we_use_cookies' config. = config. || "~~" 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
#cookie_alert_get_current_url ⇒ Object (private)
Gets the visitor's current page URL from the Cookie data
178 179 180 |
# File 'lib/cookie_alert.rb', line 178 def .signed[CookieAlert.config..to_sym].split(CookieAlert.config.)[1] end |
#cookie_alert_get_view_count ⇒ Object (private)
Gets the number of views from the Cookie data
173 174 175 |
# File 'lib/cookie_alert.rb', line 173 def .signed[CookieAlert.config..to_sym].split(CookieAlert.config.)[0].to_i end |
#cookie_alert_render_nothing ⇒ Object (private)
Renders a blank template for those times when an Alert should not be displayed
168 169 170 |
# File 'lib/cookie_alert.rb', line 168 def render partial: "cookie_alert/cookies/no_response" end |
#cookie_alert_render_primary_alert ⇒ Object (private)
Renders the primary Alert template
158 159 160 |
# File 'lib/cookie_alert.rb', line 158 def render partial: CookieAlert.config.primary_alert_template end |
#cookie_alert_render_secondary_alert ⇒ Object (private)
Renders the secondary Alert remplate
163 164 165 |
# File 'lib/cookie_alert.rb', line 163 def render partial: CookieAlert.config.secondary_alert_template end |
#cookie_alert_set_accepted_cookie ⇒ Object (private)
Sets the value of the cookie to "accepted"
138 139 140 |
# File 'lib/cookie_alert.rb', line 138 def "accepted" end |
#cookie_alert_set_cookie(cookie_value = '') ⇒ Object (private)
Creates the Cookie, setting the expiry time and the data value @param cookie_value [string] data content of the Cookie
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/cookie_alert.rb', line 144 def ='' if CookieAlert.config. == 'permanent' # Set a permanent cookie .permanent.signed[CookieAlert.config..to_sym] = elsif CookieAlert.config. == 'fixed_duration' # Set a fixed duration cookie .signed[CookieAlert.config..to_sym] = { value: , expires: CookieAlert.config..days.from_now } else # Set a session cookie .signed[CookieAlert.config..to_sym] = end end |
#cookie_alert_set_display_count_cookie(num_views) ⇒ Object (private)
Set the data value of the cookie to include the number of views and the current URL @param num_views [integer] the number of time the visitor has viewed an Alert
133 134 135 |
# File 'lib/cookie_alert.rb', line 133 def num_views num_views.to_s << CookieAlert.config. << request.fullpath end |
#display_cookie_alert ⇒ Object
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 # If the visitor has not seen the warning before # set a cookie recording the first view unless .signed[CookieAlert.config..to_sym] 1 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 .signed[CookieAlert.config..to_sym] == 'accepted' # Don't display the notice else # Retrieve the number of times the Alert has been displayed from the Cookie num_views = # MUST the Visitor accept the Cookie by clicking the link? unless CookieAlert.config. # 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' # Don't display the notive else # Increment the view count & display the warning num_views + 1 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 else # Display the full alert num_views + 1 end end end end end |