Browse files

Allow enabling/disabling warnings.

  • Loading branch information...
1 parent 091558b commit 54a9763fccb75bc2e20728266ca62f73c692856f @postmodern committed Jun 24, 2011
Showing with 32 additions and 2 deletions.
  1. +32 −2 lib/warnings/mixin.rb
View
34 lib/warnings/mixin.rb
@@ -4,6 +4,33 @@
module Warnings
module Mixin
#
+ # Enables or disables warnings.
+ #
+ # @param [Boolean] mode
+ # Specifies whether warnings will be enabled or disabled.
+ #
+ # @return [Boolean]
+ # Specifies whether warnings are enabled.
+ #
+ def warnings=(mode)
+ @warnings = mode
+ end
+
+ #
+ # Determines whether warnings are enabled.
+ #
+ # @return [Boolean]
+ # Specifies whether warnings are enabled.
+ #
+ # @note
+ # Enabling `$VERBOSE` (`ruby -w`) or `$DEBUG` (`ruby -d`) will
+ # enable all warnings by default.
+ #
+ def warnings?
+ ($VERBOSE || $DEBUG) || (@warnings == true)
+ end
+
+ #
# Registers a warning.
#
# @param [String] message
@@ -15,9 +42,12 @@ module Mixin
# @return [nil]
#
def warn(message)
- super(message) if $DEBUG
+ if warnings?
+ super(message) if $DEBUG
+
+ $WARNINGS << Warning.new(message,caller)
+ end
- $WARNINGS << Warning.new(message,caller)
return nil
end
end

0 comments on commit 54a9763

Please sign in to comment.