lib/require_bench.rb in require_bench-1.0.1 vs lib/require_bench.rb in require_bench-1.0.2
- old
+ new
@@ -6,10 +6,21 @@
# This Gem
require 'require_bench/version'
module RequireBench
TIMINGS = Hash.new { |h, k| h[k] = 0.0 }
+ skips = ENV['REQUIRE_BENCH_SKIP_PATTERN']
+ if skips
+ skip_pattern = case skips
+ when /,/ then
+ Regexp.union(*skips.split(','))
+ when /\|/ then
+ Regexp.union(*skips.split('|'))
+ end
+ puts "[RequireBench] Setting REQUIRE_BENCH_SKIP_PATTERN to #{skip_pattern}"
+ end
+ SKIP_PATTERN = skips
if ENV['REQUIRE_BENCH'] == 'true'
def require_with_timing(file)
$require_bench_semaphore = true
ret = nil
@@ -28,33 +39,22 @@
module_function :require_with_timing
end
end
if ENV['REQUIRE_BENCH'] == 'true'
- skips = ENV['REQUIRE_BENCH_SKIP_PATTERN']
- if skips
- skip_pattern = case skips
- when Regexp then
- skips
- when Array then
- Regexp.new(skips.map { |x| Regexp.escape(x) }.join('|'))
- when String then
- Regexp.new(skips.split(',').map { |x| Regexp.escape(x) }.join('|'))
- end
- puts "[RequireBench] Setting REQUIRE_BENCH_SKIP_PATTERN to #{skip_pattern}"
- ENV['REQUIRE_BENCH_SKIP_PATTERN'] = skip_pattern
- end
# A Kernel hack that adds require timing to find require problems in app.
module Kernel
alias require_without_timing require
def require(file)
file = file.to_s
# Global $ variable, which is always truthy while inside the hack, is to
# prevent a scenario that might result in infinite recursion.
return require_without_timing(file) if $require_bench_semaphore
- return require_without_timing(file) if ENV['REQUIRE_BENCH_SKIP_PATTERN'] && file =~ ENV['REQUIRE_BENCH_SKIP_PATTERN']
+ if RequireBench::SKIP_PATTERN && file =~ RequireBench::SKIP_PATTERN
+ return require_without_timing(file)
+ end
RequireBench.require_with_timing(file)
end
end
end