Module: DeprecationToolkit::Warning

Extended by:
Warning
Included in:
Warning
Defined in:
lib/deprecation_toolkit/warning.rb

Instance Method Summary collapse

Instance Method Details

#deprecation_triggered?(str) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/deprecation_toolkit/warning.rb', line 40

def deprecation_triggered?(str)
  DeprecationToolkit::Configuration.warnings_treated_as_deprecation.any? { |warning| warning === str }
end

#deprecatorObject



44
45
46
47
48
49
# File 'lib/deprecation_toolkit/warning.rb', line 44

def deprecator
  @deprecator ||= ActiveSupport::Deprecation.new("next", "DeprecationToolkit::Warning").tap do |deprecator|
    deprecator.behavior = :notify
    DeprecationSubscriber.attach_to(:deprecation_toolkit_warning)
  end
end

#handle_multipart(str) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/deprecation_toolkit/warning.rb', line 25

def handle_multipart(str)
  if @buffer
    str = @buffer + str
    @buffer = nil
    return str
  end

  if two_part_warning?(str)
    @buffer = str
    return
  end

  str
end

#two_part_warning?(str) ⇒ Boolean

Ruby 2.7 has two warnings for improper use of keyword arguments that are sent in two parts Example:

/path/to/caller.rb:1: warning: Using the last argument as keyword parameters is deprecated; \ maybe ** should be added to the call /path/to/calleee.rb:1: warning: The called method ‘method_name’ is defined here

/path/to/caller.rb:1: warning: Passing the keyword argument as the last hash parameter is deprecated /path/to/calleee.rb:1: warning: The called method ‘method_name’ is defined here

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/deprecation_toolkit/warning.rb', line 18

def two_part_warning?(str)
  str.end_with?(
    "maybe ** should be added to the call\n",
    "Passing the keyword argument as the last hash parameter is deprecated\n",
  )
end