class Chef::Deprecated::Base
Constants
- BASE_URL
Attributes
Public Class Methods
Source
# File lib/chef/deprecated.rb, line 99 def deprecation_key Chef::Mixin::ConvertToClassName.convert_to_snake_case(name, "Chef::Deprecated") end
Return the deprecation key as would be used with {Chef::Deprecated.create}.
@return [String]
Source
# File lib/chef/deprecated.rb, line 37 def initialize(msg = nil, location = nil) @message = msg @location = location end
Source
# File lib/chef/deprecated.rb, line 116 def target(id, page = nil) @deprecation_id = id @doc_page = page || deprecation_key.to_s end
Set the ID and documentation page path for this deprecation.
Used in subclasses to set the data for each type of deprecation.
@example
class MyDeprecation < Base target 123, "my_deprecation" end
@param id [Integer] Deprecation
ID number. This must be unique among
all deprecations.
@param page [String, nil] Optional documentation page path. If not
specified, the deprecation key is used.
@return [void]
Public Instance Methods
Source
# File lib/chef/deprecated.rb, line 42 def link "Please see #{url} for further details and information on how to correct this problem." end
Source
# File lib/chef/deprecated.rb, line 63 def silenced? # Check if all warnings have been silenced. return true if Chef::Config[:silence_deprecation_warnings] == true # Check if this warning has been silenced by the config. return true if Chef::Config[:silence_deprecation_warnings].any? do |silence_spec| if silence_spec.is_a? Integer # Integers can end up matching the line number in the `location` string silence_spec = "CHEF-#{silence_spec}" else # Just in case someone uses a symbol in the config by mistake. silence_spec = silence_spec.to_s end # Check for a silence by deprecation name, or by location. self.class.deprecation_key == silence_spec || self.class.deprecation_id.to_s == silence_spec || "chef-#{self.class.deprecation_id}" == silence_spec.downcase || location.include?(silence_spec) end # check if this warning has been silenced by inline comment. return true if location =~ /^(.*?):(\d+):in/ && begin # Don't buffer the whole file in memory, so read it one line at a time. line_no = $2.to_i if File.exist?($1) # some stacktraces come from `eval` and not a file location_file = ::File.open($1) (line_no - 1).times { location_file.readline } # Read all the lines we don't care about. relevant_line = location_file.readline relevant_line.match?(/#.*chef:silence_deprecation($|[^:]|:#{self.class.deprecation_key})/) end end false end
Check if this deprecation has been silenced.
@return [Boolean]
Source
# File lib/chef/deprecated.rb, line 56 def to_s "Deprecation CHEF-#{self.class.deprecation_id} from #{location}\n\n #{message}\n\n#{link}" end
Render the user-visible message for this deprecation.
@return [String]
Source
# File lib/chef/deprecated.rb, line 49 def url "#{BASE_URL}#{self.class.doc_page}/" end
Render the URL for the deprecation documentation page.
@return [String]