diff --git a/lib/rhino.rb b/lib/rhino.rb index d43e2ce..ceae966 100644 --- a/lib/rhino.rb +++ b/lib/rhino.rb @@ -16,7 +16,7 @@ module Rhino end end - @@implementation_version = nil + @@implementation_version = nil # :nodoc # Helper to resolve what version of Rhino's .jar we're really using. def self.implementation_version @@implementation_version ||= begin @@ -33,6 +33,24 @@ module Rhino end end + @@silence = java.lang.Boolean.getBoolean('rhino.silence') # :nodoc + # Should we be silent - no warnings will be printed. + def self.silence?; @@silence; end + # Silence ! (... or I kill you) + def self.silence!; @@silence = true; end + + @@warnings = {} # :nodoc + + def self.warn(msg) # :nodoc + return if silence? + # only print out deprecations once (even when non-silent) + if msg[0, 13] == '[DEPRECATION]' + return nil if @@warnings[msg] + @@warnings[msg] = true + end + super # Kernel.warn + end + end require 'rhino/version' diff --git a/lib/rhino/deprecations.rb b/lib/rhino/deprecations.rb index 54576b5..3664b14 100644 --- a/lib/rhino/deprecations.rb +++ b/lib/rhino/deprecations.rb @@ -21,30 +21,19 @@ module Rhino end end - @@warnings = {} - - def self.warn(msg) # :nodoc - # only print out deprecation warnings once - if msg[0, 13] == '[DEPRECATION]' - return nil if @@warnings[msg] - @@warnings[msg] = true - end - super # Kernel.warn - end - module To # :nodoc extend self # #deprecated use {Rhino#to_ruby} instead def self.ruby(object) - Rhino.warn "[DEPRECATION] `Rhino::To.ruby` is deprecated, use `Rhino.to_ruby` instead." + warn "[DEPRECATION] `Rhino::To.ruby` is deprecated, use `Rhino.to_ruby` instead." to_ruby(object) end # #deprecated use {Rhino#to_javascript} instead def self.javascript(object, scope = nil) - Rhino.warn "[DEPRECATION] `Rhino::To.javascript` is deprecated, use `Rhino.to_javascript` instead." + warn "[DEPRECATION] `Rhino::To.javascript` is deprecated, use `Rhino.to_javascript` instead." to_javascript(object, scope) end