Sha256: 0429193e44f5dbc3c9eac8f0d552f6ea938a98299e3d0bc83951d0f20f26de2f

Contents?: true

Size: 972 Bytes

Versions: 2

Compression:

Stored size: 972 Bytes

Contents

#
# short inspect method on all objects.
#
# "abcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnop".insp
#    -> "abcdefghijklmnopabcdefghijk..."
# Model.find(1).insp 
#    -> "<Model#1>"

module Deprecation
  def self.quiet
    @quiet = true
    yield
  ensure
    @quiet = false
  end

  def self.seen
    @seen ||= {}
  end
  
  def self.report(msg, instead=nil)
    return if App.env == "production"
    return if @quiet
    return if seen[[msg, instead]]

    seen[[msg, instead]] = true
    
    msg = "#{msg} is deprecated"
    msg += "; use #{instead} instead" if instead
    msg += ". From\n\t" + caller[1,4].join("\n\t")
    STDERR.puts msg
  end
end

module Deprecation::Etest
  def test_report
    STDERR.stubs(:puts).returns(nil)
    Deprecation.report "Hey"
    Deprecation.report "Hey"
  end

  def test_quiet
    STDERR.stubs(:puts) { raise "KJH" }
    Deprecation.quiet do
      Deprecation.report "Hey"
    end
  end
end if VEX_TEST == "base"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vex-0.6.2 lib/vex/base/deprecation.rb
vex-0.4.4 lib/vex/base/deprecation.rb