Sha256: 3f5a62c52c883fd72f86f7fe525b920bd8fe6cc08332ad6c4a2f2893450a5395

Contents?: true

Size: 1.51 KB

Versions: 27

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require 'active_support/concern'
require_relative 'logging_methods'

module ExceptionHandling
  module Methods # included on models and controllers
    extend ActiveSupport::Concern
    include ExceptionHandling::LoggingMethods

    protected

    def long_controller_action_timeout
      if defined?(Rails) && Rails.respond_to?(:env) && Rails.env == 'test'
        300
      else
        30
      end
    end

    def set_current_controller
      ExceptionHandling.current_controller = self
      result = nil
      time = Benchmark.measure do
        result = yield
      end
      if time.real > long_controller_action_timeout && !['development', 'test'].include?(ExceptionHandling.email_environment)
        name = begin
                 " in #{controller_name}::#{action_name}"
               rescue
                 " "
               end
        log_error("Long controller action detected#{name} %.4fs  " % time.real)
      end
      result
    ensure
      ExceptionHandling.current_controller = nil
    end

    included do
      Deprecation3_0.deprecation_warning('ExceptionHandling::Methods', 'include LoggingMethods; in controllers, set your own around_filter to set logging context')
      if respond_to? :around_filter
        around_filter :set_current_controller
      end
    end

    class_methods do
      def set_long_controller_action_timeout(timeout)
        define_method(:long_controller_action_timeout) { timeout }
        protected :long_controller_action_timeout
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
exception_handling-2.17.0.pre.tstarck.1 lib/exception_handling/methods.rb
exception_handling-2.16.0 lib/exception_handling/methods.rb
exception_handling-2.15.0 lib/exception_handling/methods.rb
exception_handling-2.14.0 lib/exception_handling/methods.rb
exception_handling-2.14.0.pre.gk.1 lib/exception_handling/methods.rb
exception_handling-2.14.0.pre.gk.0 lib/exception_handling/methods.rb
exception_handling-2.13.0 lib/exception_handling/methods.rb
exception_handling-2.13.0.pre.dc.0 lib/exception_handling/methods.rb
exception_handling-2.12.0 lib/exception_handling/methods.rb
exception_handling-2.12.0.gfaza.1 lib/exception_handling/methods.rb
exception_handling-2.11.4.gfaza.1 lib/exception_handling/methods.rb
exception_handling-2.11.3 lib/exception_handling/methods.rb
exception_handling-2.11.2 lib/exception_handling/methods.rb
exception_handling-2.11.1 lib/exception_handling/methods.rb
exception_handling-2.11.0 lib/exception_handling/methods.rb
exception_handling-2.10.0 lib/exception_handling/methods.rb
exception_handling-2.10.0.pre.2 lib/exception_handling/methods.rb
exception_handling-2.10.0.pre.1 lib/exception_handling/methods.rb
exception_handling-2.9.0 lib/exception_handling/methods.rb
exception_handling-2.9.0.pre.1 lib/exception_handling/methods.rb