Parent

Included Modules

Deprecatable::DeprecatedMethod

DeprecatedMethod holds all the information about a method that was marked as 'deprecated' through the Deprecatable Module. The Class, method name, and the file and line number of the deprecated method are stored in DeprecatedMethod.

It also is the location in which the calls to the deprected method are stored. Each call to the deprecated method ends up with a call to ‘log_invocation’. The ‘log_invocation’ method records the CallSite of where the deprecated method was called, and the number of times that the deprecated method was called from that CallSite.

In general, the first time a deprecated method is called from a particular CallSite, the Alerter is invoked to report the invocation. All subsequent calls to the deprecated method do not alert, although the invocation count is increased. This behavior may be altered through the Deprecatable::Options instance at Deprecatable.options.

Attributes

deprecated_method_name[R]

The aliased name of the method being deprecated. This is what is called by the wrapper to invoke the original deprecated method.

Returns the String method name.

file[R]

Public: The filesystem path of the file where the deprecation took place.

Returns the String path to the file.

klass[R]

Public: The Ruby class that has the method being deprecated.

Returns the Class whos method is being deprecated.

line_number[R]

Public: The line number in the file where hte deprecation took place. This is a 1 indexed value.

Returns the Integer line number.

message[R]

Public: The additional message to output with the alerts and reports.

Returns the String message.

method[R]

Public: The method in the klass being deprecated.

Returns the Symbol of the method being deprecated.

removal_date[R]

Public: The date on which the deprecate method will be removed.

Returns the removal date.

removal_version[R]

Public: The version of the software which will no longer have the deprecated method.

Returns the version number.

Public Class Methods

new( klass, method, file, line_number, options = {} ) click to toggle source

Create a new DeprecatedMethod.

klass - The Class containing the deprecated method. method - The Symbol method name of the deprecated method. file - The String filesystem path where the deprecation took place. line_number - The Integer line in the file where hte deprecation took

place.

options - The Hash optional parameters (default: {})

:message         - A String to output along with the rest of
                   the notifcations about the deprecated
                   method.
:removal_date    - The date on which the deprecated method
                   will be removed.
:removal_version - The version on which the deprecated 
                   method will be removed.
# File lib/deprecatable/deprecated_method.rb, line 82
def initialize( klass, method, file, line_number, options = {} )
  @klass                  = klass
  @method                 = method
  @file                   = File.expand_path( file )
  @line_number            = Float(line_number).to_i
  @deprecated_method_name = "_deprecated_#{method}"
  @invocations            = 0
  @call_sites             = Hash.new
  @message                = options[:message]
  @removal_date           = options[:removal_date]
  @removal_version        = options[:removal_version]
  @to_s                   = nil
  insert_shim( self )
end

Public Instance Methods

alert( call_site ) click to toggle source

Tell the Deprecatable.alerter to alert if the number of invocations at the CallSite is less than or equal to the alert frequency.

call_site - The CallSite instance representing where this DeprecatedMethod

was invoked.

Returns nothing.

# File lib/deprecatable/deprecated_method.rb, line 130
def alert( call_site )
  if call_site.invocation_count <= ::Deprecatable.options.alert_frequency then
    ::Deprecatable.alerter.alert( self, call_site )
  end
end
call_site_count() click to toggle source

Gets the unique count of CallSites representing the unique number of locations where this DeprecatedMethod was invoked.

Returnts the Integer unique count of CallSites.

# File lib/deprecatable/deprecated_method.rb, line 157
def call_site_count
  @call_sites.size
end
call_sites() click to toggle source

Gets the lines of all the CallSites where this DeprecatedMethod was invoked.

Returns an Array of CallSite instances.

# File lib/deprecatable/deprecated_method.rb, line 140
def call_sites
  @call_sites.values
end
invocation_count() click to toggle source

Gets the sum total of all the invocations of this DeprecatedMethod.

Returns the Integer count of invocations.

# File lib/deprecatable/deprecated_method.rb, line 147
def invocation_count
  sum = 0
  @call_sites.values.each { |cs| sum += cs.invocation_count }
  return sum
end
log_invocation( file, line_number ) click to toggle source

Log the invocation of the DeprecatedMethod at the given CallSite. Alert the media.

file - The String path to the file in which the DeprecatedMethod

was invoked.

line_number - The Integer line_number in the file on which the

DeprecatedMethod was invoked.

Returns nothing.

# File lib/deprecatable/deprecated_method.rb, line 117
def log_invocation( file, line_number )
  call_site = call_site_for( file, line_number )
  call_site.increment_invocation_count
  alert( call_site )
end
to_s() click to toggle source

Format the DeprecatedMethod as a String.

Returns the DeprecatedMethod as a String.

# File lib/deprecatable/deprecated_method.rb, line 100
def to_s
  unless @to_s then
    target = @klass.kind_of?( Class ) ? "#{@klass.name}#" : "#{@klass.name}."
    @to_s = "#{target}#{@method} defined at #{@file}:#{@line_number}"
  end
  return @to_s
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.