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.
Instance Method Summary collapse
-
#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
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
#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 |