Sha256: d6a4fb3f1b103408c9cd3232202f3a84e31e0eee0d47d65c7b083245395c08b2

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

module Ahoy
  module Stores
    class BaseStore
      def initialize(options)
        @options = options
      end

      def track_visit(options)
      end

      def track_event(name, properties, options)
      end

      def visit
      end

      def authenticate(user)
        @user = user
        if visit && visit.respond_to?(:user) && !visit.user
          begin
            visit.user = user
            visit.save!
          rescue ActiveRecord::AssociationTypeMismatch
            # do nothing
          end
        end
      end

      def report_exception(e)
        Errbase.report(e)
      end

      def user
        @user ||= (controller.respond_to?(:current_user) && controller.current_user) || (controller.respond_to?(:current_resource_owner, true) && controller.send(:current_resource_owner)) || nil
      end

      def exclude?
        bot?
      end

      def generate_id
        SecureRandom.uuid
      end

      protected

      def bot?
        @bot ||= request ? Browser.new(request.user_agent).bot? : false
      end

      def request
        @request ||= @options[:request] || controller.try(:request)
      end

      def controller
        @controller ||= @options[:controller]
      end

      def ahoy
        @ahoy ||= @options[:ahoy]
      end

      def visit_properties
        ahoy.visit_properties
      end

      def set_visit_properties(visit)
        keys = visit_properties.keys
        keys.each do |key|
          visit.send(:"#{key}=", visit_properties[key]) if visit.respond_to?(:"#{key}=") && visit_properties[key]
        end
      end

      def geocode(visit)
        if Ahoy.geocode == :async
          Ahoy::GeocodeJob.perform_later(visit)
        end
      end

      def unique_exception_classes
        classes = []
        classes << ActiveRecord::RecordNotUnique if defined?(ActiveRecord::RecordNotUnique)
        classes << PG::UniqueViolation if defined?(PG::UniqueViolation)
        classes
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ahoy_matey-1.3.1 lib/ahoy/stores/base_store.rb
ahoy_matey-1.3.0 lib/ahoy/stores/base_store.rb
ahoy_matey-1.2.2 lib/ahoy/stores/base_store.rb