Sha256: bdbe8d7947c9b6126ec245acea6f97229fbaa04b32ca3cd5c65d9479341e40e2

Contents?: true

Size: 1.94 KB

Versions: 20

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

module Appsignal
  # @api private
  class Hooks
    class << self
      def register(name, hook)
        hooks[name] = hook
      end

      def load_hooks
        hooks.each do |name, hook|
          hook.try_to_install(name)
        end
      end

      def hooks
        @hooks ||= {}
      end
    end

    class Hook
      def self.register(name, hook = self)
        Appsignal::Hooks.register(name, hook.new)
      end

      def initialize
        @installed = false
      end

      def try_to_install(name)
        return unless dependencies_present?
        return if installed?

        Appsignal.logger.info("Installing #{name} hook")
        begin
          install
          @installed = true
        rescue => ex
          Appsignal.logger.error("Error while installing #{name} hook: #{ex}")
        end
      end

      def installed?
        @installed
      end

      def dependencies_present?
        raise NotImplementedError
      end

      def install
        raise NotImplementedError
      end
    end

    module Helpers
      def string_or_inspect(string_or_other)
        if string_or_other.is_a?(String)
          string_or_other
        else
          string_or_other.inspect
        end
      end

      def truncate(text)
        text.size > 200 ? "#{text[0...197]}..." : text
      end
    end
  end
end

require "appsignal/hooks/action_cable"
require "appsignal/hooks/active_support_notifications"
require "appsignal/hooks/celluloid"
require "appsignal/hooks/delayed_job"
require "appsignal/hooks/net_http"
require "appsignal/hooks/passenger"
require "appsignal/hooks/puma"
require "appsignal/hooks/rake"
require "appsignal/hooks/redis"
require "appsignal/hooks/sequel"
require "appsignal/hooks/shoryuken"
require "appsignal/hooks/sidekiq"
require "appsignal/hooks/unicorn"
require "appsignal/hooks/mongo_ruby_driver"
require "appsignal/hooks/webmachine"
require "appsignal/hooks/data_mapper"
require "appsignal/hooks/que"

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
appsignal-2.9.8-java lib/appsignal/hooks.rb
appsignal-2.9.8 lib/appsignal/hooks.rb
appsignal-2.9.7-java lib/appsignal/hooks.rb
appsignal-2.9.7 lib/appsignal/hooks.rb
appsignal-2.9.6-java lib/appsignal/hooks.rb
appsignal-2.9.6 lib/appsignal/hooks.rb
appsignal-2.9.5 lib/appsignal/hooks.rb
appsignal-2.9.5-java lib/appsignal/hooks.rb
appsignal-2.9.4 lib/appsignal/hooks.rb
appsignal-2.9.4-java lib/appsignal/hooks.rb
appsignal-2.9.3 lib/appsignal/hooks.rb
appsignal-2.9.3-java lib/appsignal/hooks.rb
appsignal-2.9.2 lib/appsignal/hooks.rb
appsignal-2.9.2-java lib/appsignal/hooks.rb
appsignal-2.9.2.alpha.1 lib/appsignal/hooks.rb
appsignal-2.9.2.alpha.1-java lib/appsignal/hooks.rb
appsignal-2.9.1-java lib/appsignal/hooks.rb
appsignal-2.9.1 lib/appsignal/hooks.rb
appsignal-2.9.0-java lib/appsignal/hooks.rb
appsignal-2.9.0 lib/appsignal/hooks.rb