Class: Module
Overview
define deprecation api
Constant Summary collapse
- DEPS =
Hash.new { |h,k| h[k] = {} }
Instance Method Summary collapse
- #infect_with_assertions(pos_prefix, neg_prefix, skip_re, map = {}) ⇒ Object
- #tu_deprecate(old, new) ⇒ Object
- #tu_deprecation_warning(old, new = nil, kaller = nil) ⇒ Object
Instance Method Details
#infect_with_assertions(pos_prefix, neg_prefix, skip_re, map = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mini/spec.rb', line 6 def infect_with_assertions pos_prefix, neg_prefix, skip_re, map = {} Mini::Assertions.public_instance_methods(false).each do |meth| meth = meth.to_s new_name = case meth when /^assert/ then meth.sub(/^assert/, pos_prefix.to_s) when /^refute/ then meth.sub(/^refute/, neg_prefix.to_s) end next unless new_name next if new_name =~ skip_re regexp, replacement = map.find { |re, _| new_name =~ re } new_name.sub! regexp, replacement if replacement # warn "%-22p -> %p %p" % [meth, new_name, regexp] self.class_eval <<-EOM def #{new_name} *args, &block return Mini::Spec.current.#{meth}(*args, &self) if Proc === self return Mini::Spec.current.#{meth}(args.first, self) if args.size == 1 return Mini::Spec.current.#{meth}(self, *args) end EOM end end |
#tu_deprecate(old, new) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/test/unit/deprecate.rb', line 15 def tu_deprecate old, new class_eval <<-EOM def #{old} *args, &block cls, clr = self.class, caller.first self.class.tu_deprecation_warning #{old.inspect}, #{new.inspect}, clr #{new}(*args, &block) end EOM end |
#tu_deprecation_warning(old, new = nil, kaller = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/test/unit/deprecate.rb', line 4 def tu_deprecation_warning old, new = nil, kaller = nil kaller ||= caller[1] unless DEPS[old][kaller] then msg = "#{self}##{old} deprecated. " msg += new ? "Use ##{new}" : "No replacement is provided" msg += ". From #{kaller}." warn msg end DEPS[old][kaller] = true end |