Module: Skylight::Core::Probes Private

Defined in:
lib/skylight/core/probes.rb,
lib/skylight/core/probes/tilt.rb,
lib/skylight/core/probes/excon.rb,
lib/skylight/core/probes/mongo.rb,
lib/skylight/core/probes/moped.rb,
lib/skylight/core/probes/redis.rb,
lib/skylight/core/probes/sequel.rb,
lib/skylight/core/probes/faraday.rb,
lib/skylight/core/probes/mongoid.rb,
lib/skylight/core/probes/sinatra.rb,
lib/skylight/core/probes/net_http.rb,
lib/skylight/core/probes/active_job.rb,
lib/skylight/core/probes/httpclient.rb,
lib/skylight/core/probes/middleware.rb,
lib/skylight/core/probes/action_view.rb,
lib/skylight/core/probes/elasticsearch.rb,
lib/skylight/core/probes/excon/middleware.rb,
lib/skylight/core/probes/action_controller.rb,
lib/skylight/core/probes/active_job_enqueue.rb,
lib/skylight/core/probes/active_model_serializers.rb,
lib/skylight/core/probes/action_dispatch/request_id.rb,
lib/skylight/core/probes/action_dispatch/routing/route_set.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

Modules: ActionController, ActionDispatch, ActionView, ActiveJob, ActiveModelSerializers, Elasticsearch, Excon, Faraday, HTTPClient, Middleware, Mongo, Mongoid, Moped, NetHTTP, Redis, Sequel, Sinatra, Tilt Classes: ProbeRegistration

Class Method Summary collapse

Class Method Details

.add_path(path) ⇒ 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
# File 'lib/skylight/core/probes.rb', line 27

def add_path(path)
  root = Pathname.new(path)
  Pathname.glob(root.join("./**/*.rb")).each do |f|
    name = f.relative_path_from(root).sub_ext('').to_s
    if available.key?(name)
      raise "duplicate probe name: #{name}; original=#{available[name]}; new=#{f}"
    end
    available[name] = f
  end
end

.availableObject

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.



38
39
40
# File 'lib/skylight/core/probes.rb', line 38

def available
  @available ||= {}
end

.installedObject

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.



57
58
59
# File 'lib/skylight/core/probes.rb', line 57

def installed
  @installed ||= {}
end

.is_available?(klass_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)


61
62
63
# File 'lib/skylight/core/probes.rb', line 61

def is_available?(klass_name)
  !!Skylight::Core::Util::Inflector.safe_constantize(klass_name)
end

.lookup_by_require_path(require_path) ⇒ 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.



102
103
104
# File 'lib/skylight/core/probes.rb', line 102

def lookup_by_require_path(require_path)
  require_hooks[require_path]
end

.pathsObject

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/skylight/core/probes.rb', line 23

def paths
  @paths ||= []
end

.probe(*probes) ⇒ 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.



42
43
44
45
46
47
48
49
50
51
# File 'lib/skylight/core/probes.rb', line 42

def probe(*probes)
  unknown = probes.map(&:to_s) - available.keys
  unless unknown.empty?
    raise ArgumentError, "unknown probes: #{unknown.join(', ')}"
  end

  probes.each do |p|
    require available[p.to_s]
  end
end

.register(name, *args) ⇒ 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.



65
66
67
68
69
70
71
72
73
74
# File 'lib/skylight/core/probes.rb', line 65

def register(name, *args)
  registration = ProbeRegistration.new(name, *args)

  if is_available?(registration.klass_name)
    installed[registration.klass_name] = registration
    registration.install
  else
    register_require_hook(registration)
  end
end

.register_require_hook(registration) ⇒ 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.



90
91
92
93
94
# File 'lib/skylight/core/probes.rb', line 90

def register_require_hook(registration)
  registration.require_paths.each do |p|
    require_hooks[p] = registration
  end
end

.require_hook(require_path) ⇒ 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.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/skylight/core/probes.rb', line 76

def require_hook(require_path)
  registration = lookup_by_require_path(require_path)
  return unless registration

  # Double check constant is available
  if is_available?(registration.klass_name)
    installed[registration.klass_name] = registration
    registration.install

    # Don't need this to be called again
    unregister_require_hook(registration)
  end
end

.require_hooksObject

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.



53
54
55
# File 'lib/skylight/core/probes.rb', line 53

def require_hooks
  @require_hooks ||= {}
end

.unregister_require_hook(registration) ⇒ 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.



96
97
98
99
100
# File 'lib/skylight/core/probes.rb', line 96

def unregister_require_hook(registration)
  registration.require_paths.each do |p|
    require_hooks.delete(p)
  end
end