Sha256: 18a845810811764582dde7e41886f815e300fc4d2ec19c7dcf88201f4b8c0ab4

Contents?: true

Size: 1.32 KB

Versions: 23

Compression:

Stored size: 1.32 KB

Contents

module Appsignal
  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 try_to_install(name)
        if dependencies_present? && !installed?
          Appsignal.logger.info("Installing #{name} hook")
          begin
            install
            @installed = true
          rescue => ex
            Appsignal.logger.error("Error while installing #{name} hook: #{ex}")
          end
        end
      end

      def installed?
        !! @installed
      end

      def dependencies_present?
        raise NotImplementedError
      end

      def install
        raise NotImplementedError
      end
    end
  end
end

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/sidekiq'
require 'appsignal/hooks/unicorn'
require 'appsignal/hooks/mongo_ruby_driver'

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
appsignal-1.0.1 lib/appsignal/hooks.rb
appsignal-1.0.0 lib/appsignal/hooks.rb
appsignal-1.0.0.rc.1 lib/appsignal/hooks.rb