Sha256: cd2b19bada00cd9e1b3b23cb4aa70ec1fd80b41afb94749b2c5e97816d5791a4

Contents?: true

Size: 678 Bytes

Versions: 6

Compression:

Stored size: 678 Bytes

Contents

module StaticMatic
  module Deprecation
    def deprecate(options = {})
      message = "#{caller_method_name} has been deprecated and will be removed."
      message << %Q{ Please use "#{options[:alt]}" instead } if options[:alt]
      
      logger.warn(message)
    end
    
  private
    
    # Thanks to http://snippets.dzone.com/posts/show/2787 for this nugget
    def caller_method_name
      parse_caller(caller(2).first).last
    end

    def parse_caller(at)
      if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
        file = Regexp.last_match[1]
    		line = Regexp.last_match[2].to_i
    		method = Regexp.last_match[3]
    		[file, line, method]
    	end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tdreyno-staticmatic-2.0.3 lib/staticmatic/deprecation.rb
tdreyno-staticmatic-2.1.0 lib/staticmatic/deprecation.rb
tdreyno-staticmatic-2.1.1 lib/staticmatic/deprecation.rb
tdreyno-staticmatic-2.1.3 lib/staticmatic/deprecation.rb
tdreyno-staticmatic-2.1.4 lib/staticmatic/deprecation.rb
tdreyno-staticmatic-2.9.0 lib/staticmatic/deprecation.rb