Class: Rbcli::DeprecationWarning

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcli/util/deprecation_warning.rb

Constant Summary collapse

@@warnings =
[]
@@errors_exist =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_feature_name, message_text, change_by_version, caller) ⇒ DeprecationWarning

Returns a new instance of DeprecationWarning.



27
28
29
30
31
32
33
34
# File 'lib/rbcli/util/deprecation_warning.rb', line 27

def initialize original_feature_name, message_text, change_by_version, caller
  #@caller = caller_locations(2,1)[0].label
  @original_feature_name = original_feature_name
  @message_text = message_text
  @change_by_version = change_by_version
  @caller = caller
  @@warnings.append self
end

Class Method Details

.display_warningsObject



56
57
58
59
# File 'lib/rbcli/util/deprecation_warning.rb', line 56

def self.display_warnings
  @@warnings.each { |w| w.display }
  exit(1) if @@errors_exist
end

Instance Method Details

#displayObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rbcli/util/deprecation_warning.rb', line 36

def display
  deprecated_version_parts = @change_by_version.split('.').map { |i| i.to_i }
  current_version_parts = Rbcli::VERSION.split('.').map { |i| i.to_i }

  if deprecated_version_parts[0] > current_version_parts[0] or
      deprecated_version_parts[1] > current_version_parts[1] or
      deprecated_version_parts[2] >= current_version_parts[2]

    message = "DEPRECATION ERROR: The feature `#{@original_feature_name}` has been deprecated as of Rbcli version #{@change_by_version}. #{@message_text} Please update the relevant code to continue using Rbcli."
    Rbcli::log.error { message }
    puts message.red
    @@errors_exist = true
  else
    message = "DEPRECATION WARNING: The feature `#{@original_feature_name}` has been deprecated. #{@message_text} This feature will be removed in version #{@change_by_version}."
    Rbcli::log.warn { message }
    puts message.yellow
  end
  puts @caller[0], ""
end