Class: Dont::Deprecation

Inherits:
Object
  • Object
show all
Defined in:
lib/dont.rb

Overview

Contains info about the deprecated method being called

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject:, old_method:, new_method: nil) ⇒ Deprecation

Returns a new instance of Deprecation.



112
113
114
115
116
# File 'lib/dont.rb', line 112

def initialize(subject:, old_method:, new_method: nil)
  @subject = subject
  @new_method = new_method
  @old_method = old_method
end

Instance Attribute Details

#new_methodObject (readonly)

Returns the value of attribute new_method.



110
111
112
# File 'lib/dont.rb', line 110

def new_method
  @new_method
end

#old_methodObject (readonly)

Returns the value of attribute old_method.



110
111
112
# File 'lib/dont.rb', line 110

def old_method
  @old_method
end

#subjectObject (readonly)

Returns the value of attribute subject.



110
111
112
# File 'lib/dont.rb', line 110

def subject
  @subject
end

Instance Method Details

#messageString

A message saying that the old_method is deprecated. It also mentions the new_method if provided.

Returns:

  • (String)


122
123
124
125
126
127
128
129
# File 'lib/dont.rb', line 122

def message
  klass = subject.class.name
  if new_method && !new_method.empty?
    "DEPRECATED: Don't use #{klass}##{old_method}. It's deprecated in favor of #{new_method}."
  else
    "DEPRECATED: Don't use #{klass}##{old_method}. It's deprecated."
  end
end