Skip to content

Commit

Permalink
Strongly type SimpleInstrumentor
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Nov 16, 2023
1 parent 9773166 commit 488a750
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions common/lib/dependabot/simple_instrumentor.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# typed: true
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"

module Dependabot
module SimpleInstrumentor
class << self
attr_accessor :events, :subscribers
extend T::Sig

sig { returns(T.nilable(T::Array[T.proc.params(name: String, params: T::Hash[Symbol, T.untyped]).void])) }
attr_accessor :subscribers

sig { params(block: T.proc.params(name: String, params: T::Hash[Symbol, T.untyped]).void).void }
def subscribe(&block)
@subscribers ||= []
@subscribers ||= T.let(
[],
T.nilable(T::Array[T.proc.params(name: String, params: T::Hash[Symbol, T.untyped]).void])
)
@subscribers << block
end

sig { params(name: String, params: T::Hash[Symbol, T.untyped], block: T.proc.void).void }
def instrument(name, params = {}, &block)
@subscribers&.each { |s| s.call(name, params) }
yield if block
Expand Down

0 comments on commit 488a750

Please sign in to comment.