Class: Rbcli::DeprecationWarning

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

Instance Method Summary collapse

Constructor Details

#initialize(offending_object, warn_at: nil, deprecate_at: nil, message: nil) ⇒ DeprecationWarning

Returns a new instance of DeprecationWarning.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rbcli/util/deprecation_warning.rb', line 9

def initialize offending_object, warn_at: nil, deprecate_at: nil, message: nil
  if offending_object.is_a?(String)
    @offender = offending_object
    @in_rbcli = offending_object.include?('Rbcli')
  else
    @offender = (offending_object.respond_to?(:name) && offending_object.name.include?('::')) ? @offender = offending_object.name : @offender = offending_object.class.name
    @in_rbcli = offending_object.name.include?('Rbcli')
  end
  # @method = self.caller_locations[1].label
  @message = message

  raise Rbcli::ConfigurateError.new "The `warn_at` and `deprecate_at` values must both be set" if warn_at.nil? || deprecate_at.nil?
  raise Rbcli::ConfigurateError.new "Version string must be set in Rbcli::Configurate.cli to use deprecation warnings" if !@in_rbcli && Rbcli::Warehouse.get(:version, :appinfo).nil?
  @current_version = @in_rbcli ? Rbcli::VERSION : Gem::Version.new(Rbcli::Warehouse.get(:version, :appinfo))
  @warning_version = Gem::Version.new(warn_at)
  @error_version = Gem::Version.new(deprecate_at)
  raise Rbcli::ConfigurateError.new "Warning version must come earlier than the deprecation version" if @warning_version >= @error_version

  @callerstack = self.caller_locations
  self.parse
end