rug-b

Get Version

0.1.0

→ ‘structured_warnings’

What

This is an implementation of Daniel Berger ’s proposal of structured warnings for Ruby. They provide dynamic suppression and activation, as well as, an inheritance hierarchy to model their relations. This library preserves the old warn signature, but additionally allows a raise-like use.

For more information on the usage and benefits of this library have a look at the inspiring article at O’Reilly.

Installing

sudo gem install structured_warnings

Demonstration of usage

To get you started – here a short extract from the article:

class Foo
  def old_method
    warn DeprecatedMethodWarning, 'This method is deprecated. Use new_method instead'
    # Do stuff
  end
end


require 'test/unit'
require 'structured_warnings'

class FooTests < Test::Unit::TestCase
  def setup
    @foo = Foo.new
  end

  def test_old_method
    assert_warn(DeprecatedMethodWarning){ @foo.old_method }
  end
end

[...]

So, using our hypothetical RedefinedMethodWarning class, I could disable them like so:

RedefinedMethodWarning.disable # No more warnings about method redefinitions!

Or, with block syntax, we could disable a particular warning temporarily:

# Don't bug me about deprecated method warnings within this block, I know
# what I'm doing.
#
DeprecatedMethodWarning.disable{
   [1,2,3,4,5].indexes(1,3) # Array#indexes is a deprecated method
}

# But here I would get a warning since it's outside the block:
[1,2,3,4,5].indexes(1,3)

How to submit patches

Read the 8 steps for fixing other people’s code and for section 8z: Email the project owner, use the Email below.

The trunk repository is svn://rubyforge.org/var/svn/rug-b/structured_warnings/trunk for anonymous access.

License

This code is free to use under the terms of the MIT license.

Contact

Comments are welcome. Send an email to Gregor Schmidt

Gregor Schmidt, 21st February 2008
Theme extended from Paul Battley