Extract instrumentation plumbing
This commit is contained in:
Родитель
d6a7473d25
Коммит
62929e36ba
|
@ -8,6 +8,9 @@ module GitHub
|
|||
require 'github/ldap/posix_group'
|
||||
require 'github/ldap/virtual_group'
|
||||
require 'github/ldap/virtual_attributes'
|
||||
require 'github/ldap/instrumentation'
|
||||
|
||||
include Instrumentation
|
||||
|
||||
extend Forwardable
|
||||
|
||||
|
@ -189,18 +192,5 @@ module GitHub
|
|||
VirtualAttributes.new(false)
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Instrument the block if an instrumentation servie is set.
|
||||
#
|
||||
# Returns the result of the block.
|
||||
def instrument(event, payload = {})
|
||||
if instrumentation_service
|
||||
instrumentation_service.instrument(event, payload) do
|
||||
yield payload
|
||||
end
|
||||
else
|
||||
yield payload
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
module GitHub
|
||||
class Ldap
|
||||
# Encapsulates common instrumentation behavior.
|
||||
class Instrumentation
|
||||
attr_reader :instrumentation_service
|
||||
private :instrumentation_service
|
||||
|
||||
# Internal: Instrument a block with the defined instrumentation service.
|
||||
#
|
||||
# Yields the event payload if a block is given.
|
||||
#
|
||||
# Skips instrumentation if no service is set.
|
||||
#
|
||||
# Returns the return value of the block.
|
||||
def instrument(event, payload = {})
|
||||
if instrumentation_service
|
||||
instrumentation_service.instrument(event, payload) do |payload|
|
||||
payload[:result] = yield(payload) if block_given?
|
||||
end
|
||||
else
|
||||
yield(payload) if block_given?
|
||||
end
|
||||
end
|
||||
private :instrument
|
||||
end
|
||||
end
|
||||
end
|
Загрузка…
Ссылка в новой задаче