Renamed ahoy controller extensions
Andrew Kane
committed Mar 02, 2014
commit d648d75afccb6aebf1c9222642feb33362034e59
Showing 3
changed files with
33 additions
and 19 deletions
ahoy/controller.rb b/lib/ahoy/controller.rb
+17
-0
| @@ | @@ -0,0 +1,17 @@ |
| + | module Ahoy |
| + | module ControllerExtensions |
| + | |
| + | def self.included(base) |
| + | base.helper_method :current_visit |
| + | end |
| + | |
| + | protected |
| + | |
| + | def current_visit |
| + | if cookies[:ahoy_visit] |
| + | @current_visit ||= Ahoy::Visit.where(visit_token: cookies[:ahoy_visit]).first |
| + | end |
| + | end |
| + | |
| + | end |
| + | end |
ahoy/controller_extensions.rb b/lib/ahoy/controller_extensions.rb
+0
-17
| @@ | @@ -1,17 +0,0 @@ |
| - | module Ahoy |
| - | module ControllerExtensions |
| - | |
| - | def self.included(base) |
| - | base.helper_method :current_visit |
| - | end |
| - | |
| - | protected |
| - | |
| - | def current_visit |
| - | if cookies[:ahoy_visit] |
| - | @current_visit ||= Ahoy::Visit.where(visit_token: cookies[:ahoy_visit]).first |
| - | end |
| - | end |
| - | |
| - | end |
| - | end |
ahoy_matey.rb b/lib/ahoy_matey.rb
+16
-2
| @@ | @@ -1,5 +1,5 @@ |
| require "ahoy/version" | |
| - | require "ahoy/controller_extensions" |
| + | require "ahoy/controller" |
| require "addressable/uri" | |
| require "browser" | |
| require "geocoder" | |
| @@ | @@ -11,4 +11,18 @@ module Ahoy |
| end | |
| end | |
| - | ActionController::Base.send :include, Ahoy::ControllerExtensions |
| + | ActionController::Base.send :include, Ahoy::Controller |
| + | |
| + | if defined?(Warden) |
| + | Warden::Manager.after_authentication do |user, auth, opts| |
| + | p user |
| + | p auth.env |
| + | p opts |
| + | request = Rack::Request.new(auth.env) |
| + | if request.cookies["ahoy_visit"] |
| + | visit = Ahoy::Visit.where(visit_token: request.cookies["ahoy_visit"]).first |
| + | visit.user = user |
| + | visit.save! |
| + | end |
| + | end |
| + | end |