lib/ahoy_matey.rb in ahoy_matey-0.0.4 vs lib/ahoy_matey.rb in ahoy_matey-0.1.0
- old
+ new
@@ -1,28 +1,33 @@
-require "ahoy/version"
-require "ahoy/controller"
require "addressable/uri"
require "browser"
require "geocoder"
require "referer-parser"
+require "request_store"
+require "ahoy/version"
+require "ahoy/controller"
+require "ahoy/model"
+require "ahoy/engine"
module Ahoy
- class Engine < ::Rails::Engine
- isolate_namespace Ahoy
+
+ def self.visit_model
+ ::Visit
end
+
end
ActionController::Base.send :include, Ahoy::Controller
+ActiveRecord::Base.send(:extend, Ahoy::Model) if defined?(ActiveRecord)
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!
+ visit = Ahoy.visit_model.where(visit_token: request.cookies["ahoy_visit"]).first
+ if visit
+ visit.user = user
+ visit.save!
+ end
end
end
end