Added support for Doorkeeper

Andrew Kane committed May 02, 2014
commit 3bc5b9c706fb9deb3df998e4cbe5bf4796279417
Showing 3 changed files with 16 additions and 1 deletions
app/controllers/ahoy/base_controller.rb +2 -0
@@ @@ -1,5 +1,7 @@
module Ahoy
class BaseController < ApplicationController
+ include Doorkeeper::Helpers::Filter if defined?(Doorkeeper)
+
# skip all filters
skip_filter *_process_action_callbacks.map(&:filter)
app/controllers/ahoy/visits_controller.rb +1 -1
@@ @@ -13,7 +13,7 @@ module Ahoy
v.user_agent = request.user_agent if v.respond_to?(:user_agent=)
v.referrer = params[:referrer] if v.respond_to?(:referrer=)
v.landing_page = params[:landing_page] if v.respond_to?(:landing_page=)
- v.user = current_user if respond_to?(:current_user) and v.respond_to?(:user=)
+ v.user = Ahoy.fetch_user(self) if v.respond_to?(:user=)
v.platform = params[:platform] if v.respond_to?(:platform=)
v.app_version = params[:app_version] if v.respond_to?(:app_version=)
v.os_version = params[:os_version] if v.respond_to?(:os_version=)
ahoy_matey.rb b/lib/ahoy_matey.rb +13 -0
@@ @@ -24,6 +24,19 @@ module Ahoy
@referrer_parser ||= RefererParser::Referer.new("https://github.com/ankane/ahoy")
end
+ def self.fetch_user(controller)
+ if user_method.respond_to?(:call)
+ user_method.call(controller)
+ else
+ controller.send(user_method)
+ end
+ end
+
+ mattr_accessor :user_method
+ self.user_method = proc do |controller|
+ (controller.respond_to?(:current_user) && controller.current_user) || (controller.respond_to?(:current_resource_owner, true) and controller.send(:current_resource_owner))
+ end
+
end
ActionController::Base.send :include, Ahoy::Controller