Method: Chef::Deprecated::Base#silenced?
- Defined in:
- lib/chef/deprecated.rb
#silenced? ⇒ Boolean
Check if this deprecation has been silenced.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 |