Skip to content

Commit 62929e3

Browse files
committed
Extract instrumentation plumbing
1 parent d6a7473 commit 62929e3

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

lib/github/ldap.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class Ldap
88
require 'github/ldap/posix_group'
99
require 'github/ldap/virtual_group'
1010
require 'github/ldap/virtual_attributes'
11+
require 'github/ldap/instrumentation'
12+
13+
include Instrumentation
1114

1215
extend Forwardable
1316

@@ -189,18 +192,5 @@ def configure_virtual_attributes(attributes)
189192
VirtualAttributes.new(false)
190193
end
191194
end
192-
193-
# Internal: Instrument the block if an instrumentation servie is set.
194-
#
195-
# Returns the result of the block.
196-
def instrument(event, payload = {})
197-
if instrumentation_service
198-
instrumentation_service.instrument(event, payload) do
199-
yield payload
200-
end
201-
else
202-
yield payload
203-
end
204-
end
205195
end
206196
end

lib/github/ldap/instrumentation.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module GitHub
2+
class Ldap
3+
# Encapsulates common instrumentation behavior.
4+
class Instrumentation
5+
attr_reader :instrumentation_service
6+
private :instrumentation_service
7+
8+
# Internal: Instrument a block with the defined instrumentation service.
9+
#
10+
# Yields the event payload if a block is given.
11+
#
12+
# Skips instrumentation if no service is set.
13+
#
14+
# Returns the return value of the block.
15+
def instrument(event, payload = {})
16+
if instrumentation_service
17+
instrumentation_service.instrument(event, payload) do |payload|
18+
payload[:result] = yield(payload) if block_given?
19+
end
20+
else
21+
yield(payload) if block_given?
22+
end
23+
end
24+
private :instrument
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy