class Google::Ads::GoogleAds::Deprecation

Constants

Error

Public Class Methods

new( treat_deprecation_warnings_as_errors, warn_on_all_deprecations ) click to toggle source
# File lib/google/ads/google_ads/deprecation.rb, line 6
def initialize(
  treat_deprecation_warnings_as_errors,
  warn_on_all_deprecations
)
  @treat_deprecation_warnings_as_errors = treat_deprecation_warnings_as_errors
  @warn_on_all_deprecations = warn_on_all_deprecations
  @silenced_sites = {}
end

Public Instance Methods

deprecate(deprecation) click to toggle source
# File lib/google/ads/google_ads/deprecation.rb, line 15
def deprecate(deprecation)
  return unless should_warn?
  if @treat_deprecation_warnings_as_errors
    raise Error, deprecation
  else
    Warning.warn("\n#{deprecation}. Called from: #{CallerFilter.first_non_google_ads_line}\n")
  end
end

Private Instance Methods

should_warn?() click to toggle source

Determines if we should issue a deprecation warning, silencing on each user call site after the first warning.

# File lib/google/ads/google_ads/deprecation.rb, line 28
def should_warn?
  return true if @warn_on_all_deprecations

  if !@silenced_sites.include?(CallerFilter.first_non_google_ads_line)
    @silenced_sites[CallerFilter.first_non_google_ads_line] ||= true
    true
  else
    false
  end
end