Module: Appsignal::Loaders Private

Defined in:
lib/appsignal/loaders.rb,
lib/appsignal/loaders/grape.rb,
lib/appsignal/loaders/hanami.rb,
lib/appsignal/loaders/padrino.rb,
lib/appsignal/loaders/sinatra.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: GrapeLoader, HanamiLoader, Loader, PadrinoLoader, SinatraLoader

Class Method Summary collapse

Class Method Details

.instancesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/appsignal/loaders.rb', line 11

def instances
  @instances ||= {}
end

.load(name_str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/appsignal/loaders.rb', line 27

def load(name_str)
  name = name_str.to_sym

  unless registered?(name)
    require_loader(name)
    unless registered?(name)
      Appsignal.internal_logger
        .warn("No loader found with the name '#{name}'.")
      return
    end
  end

  Appsignal.internal_logger.debug("Loading '#{name}' loader")

  begin
    loader_klass = loaders[name]
    loader = loader_klass.new
    instances[name] = loader
    loader.on_load if loader.respond_to?(:on_load)
  rescue => e
    Appsignal.internal_logger.error(
      "An error occurred while loading the '#{name}' loader: " \
        "#{e.class}: #{e.message}\n#{e.backtrace}"
    )
  end
end

.loadersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
# File 'lib/appsignal/loaders.rb', line 7

def loaders
  @loaders ||= {}
end

.register(name, klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/appsignal/loaders.rb', line 15

def register(name, klass)
  loaders[name.to_sym] = klass
end

.registered?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


19
20
21
# File 'lib/appsignal/loaders.rb', line 19

def registered?(name)
  loaders.key?(name)
end

.startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/appsignal/loaders.rb', line 54

def start
  instances.each do |name, instance|
    Appsignal.internal_logger.debug("Starting '#{name}' loader")
    begin
      instance.on_start if instance.respond_to?(:on_start)
    rescue => e
      Appsignal.internal_logger.error(
        "An error occurred while starting the '#{name}' loader: " \
          "#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
      )
    end
  end
end

.unregister(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# File 'lib/appsignal/loaders.rb', line 23

def unregister(name)
  loaders.delete(name)
end