Class: Chef::Deprecated::Base
- Inherits:
-
Object
- Object
- Chef::Deprecated::Base
- Defined in:
- lib/chef/deprecated.rb
Direct Known Subclasses
ArchiveFileIntegerFileMode, AttributeBlacklistConfiguration, AttributeWhitelistConfiguration, Attributes, ChefPlatformMethods, ChefRest, ChefSugar, CustomResource, DeployResource, DnfPackageAllowDowngrade, EasyInstall, ErlResource, ExitCode, FreebsdPkgProvider, Generic, InternalApi, JsonAutoInflate, KnifeBootstrapApis, LaunchdHashProperty, LocalListen, LocaleLcAll, MultiresourceMatch, NamespaceCollisions, PackageMisc, PolicyfileCompatMode, Property, PropertyNameCollision, ResourceNameWithoutProvides, RunCommand, ShellOut, SupportsProperty, UnifiedMode, UseInlineResources, VerifyFile
Constant Summary collapse
- BASE_URL =
"https://docs.chef.io/deprecations_".freeze
Class Attribute Summary collapse
-
.deprecation_id ⇒ Object
readonly
Returns the value of attribute deprecation_id.
-
.doc_page ⇒ Object
readonly
Returns the value of attribute doc_page.
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Class Method Summary collapse
-
.deprecation_key ⇒ String
Return the deprecation key as would be used with create.
-
.target(id, page = nil) ⇒ void
Set the ID and documentation page path for this deprecation.
Instance Method Summary collapse
-
#initialize(msg = nil, location = nil) ⇒ Base
constructor
A new instance of Base.
- #link ⇒ Object
-
#silenced? ⇒ Boolean
Check if this deprecation has been silenced.
-
#to_s ⇒ String
Render the user-visible message for this deprecation.
-
#url ⇒ String
Render the URL for the deprecation documentation page.
Constructor Details
#initialize(msg = nil, location = nil) ⇒ Base
Returns a new instance of Base.
37 38 39 40 |
# File 'lib/chef/deprecated.rb', line 37 def initialize(msg = nil, location = nil) @message = msg @location = location end |
Class Attribute Details
.deprecation_id ⇒ Object (readonly)
Returns the value of attribute deprecation_id.
94 95 96 |
# File 'lib/chef/deprecated.rb', line 94 def deprecation_id @deprecation_id end |
.doc_page ⇒ Object (readonly)
Returns the value of attribute doc_page.
94 95 96 |
# File 'lib/chef/deprecated.rb', line 94 def doc_page @doc_page end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
35 36 37 |
# File 'lib/chef/deprecated.rb', line 35 def location @location end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
35 36 37 |
# File 'lib/chef/deprecated.rb', line 35 def @message end |
Class Method Details
.deprecation_key ⇒ String
Return the deprecation key as would be used with Chef::Deprecated.create.
99 100 101 |
# File 'lib/chef/deprecated.rb', line 99 def deprecation_key Chef::Mixin::ConvertToClassName.convert_to_snake_case(name, "Chef::Deprecated") end |
.target(id, page = nil) ⇒ void
This method returns an undefined value.
Set the ID and documentation page path for this deprecation.
Used in subclasses to set the data for each type of deprecation.
116 117 118 119 |
# File 'lib/chef/deprecated.rb', line 116 def target(id, page = nil) @deprecation_id = id @doc_page = page || deprecation_key.to_s end |
Instance Method Details
#link ⇒ Object
42 43 44 |
# File 'lib/chef/deprecated.rb', line 42 def link "Please see #{url} for further details and information on how to correct this problem." end |
#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 |
#to_s ⇒ String
Render the user-visible message for this deprecation.
56 57 58 |
# File 'lib/chef/deprecated.rb', line 56 def to_s "Deprecation CHEF-#{self.class.deprecation_id} from #{location}\n\n #{}\n\n#{link}" end |