1
0
Fork 0
mirror of https://github.com/rubyjs/therubyrhino synced 2023-03-27 23:21:34 -04:00

move warn out of deprecations + allow for (warn) silence!

This commit is contained in:
kares 2012-12-05 10:01:25 +01:00
parent 05ece36c5d
commit 24eb2ab70c
2 changed files with 21 additions and 14 deletions

View file

@ -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'

View file

@ -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