Module: Datadog::Patcher::CommonMethods
- Included in:
- Datadog::Patcher
- Defined in:
- lib/ddtrace/patcher.rb
Overview
Defines some common methods for patching, that can be used at the instance, class, or module level.
Instance Method Summary collapse
- #do_once(key = nil, options = {}) ⇒ Object
- #done?(key, options = {}) ⇒ Boolean
- #without_warnings ⇒ Object
Instance Method Details
#do_once(key = nil, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ddtrace/patcher.rb', line 39 def do_once(key = nil, = {}) DO_ONCE_USAGE_WARN_ONLY_ONCE.run do Datadog.logger.warn('Datadog::Patcher#do_once is deprecated. Use Datadog::Utils::OnlyOnce instead.') end # If already done, don't do again @done_once ||= Hash.new { |h, k| h[k] = {} } return @done_once[key][[:for]] if @done_once.key?(key) && @done_once[key].key?([:for]) # Otherwise 'do' yield.tap do # Then add the key so we don't do again. @done_once[key][[:for]] = true end end |
#done?(key, options = {}) ⇒ Boolean
55 56 57 58 59 60 61 62 63 |
# File 'lib/ddtrace/patcher.rb', line 55 def done?(key, = {}) DO_ONCE_USAGE_WARN_ONLY_ONCE.run do Datadog.logger.warn('Datadog::Patcher#done? is deprecated. Use Datadog::Utils::OnlyOnce instead.') end return false unless instance_variable_defined?(:@done_once) !@done_once.nil? && @done_once.key?(key) && @done_once[key].key?([:for]) end |
#without_warnings ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ddtrace/patcher.rb', line 27 def without_warnings # This is typically used when monkey patching functions such as # intialize, which Ruby advices you not to. Use cautiously. v = $VERBOSE $VERBOSE = nil begin yield ensure $VERBOSE = v end end |