Module: Kernel

Defined in:
lib/require_bench.rb

Overview

A Kernel hack that adds require timing to find require problems in app.

Instance Method Summary collapse

Instance Method Details

#_require_bench_consume_file(type, file, *args) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/require_bench.rb', line 152

def _require_bench_consume_file(type, file, *args)
  file_path = file.to_s
  # byebug if file_path.match?(/no_group_fox/)

  # Global $ variable, which is always truthy while inside the hack, is to
  #   prevent a scenario that might result in infinite recursion.
  return send("#{type}_without_timing", file_path, *args) if $require_bench_semaphore

  short_type = type[0]
  measure = RequireBench::INCLUDE_PATTERN && file_path.match?(RequireBench::INCLUDE_PATTERN)
  skippy = RequireBench::SKIP_PATTERN && file_path.match?(RequireBench::SKIP_PATTERN)
  RequireBench::PRINTER.out_start(file, short_type) if RequireBench::LOG_START
  if RequireBench::RESCUED_CLASSES.any?
    begin
      _require_bench_file(type, measure, skippy, file_path, *args)
    rescue *RequireBench::RESCUED_CLASSES => e
      RequireBench::PRINTER.out_error(e, file, short_type, *args)
    end
  else
    _require_bench_file(type, measure, skippy, file_path, *args)
  end
end

#_require_bench_file(type, measure, skippy, file_path, *args) ⇒ Object



175
176
177
178
179
180
181
182
183
# File 'lib/require_bench.rb', line 175

def _require_bench_file(type, measure, skippy, file_path, *args)
  if !measure && skippy
    send("#{type}_without_timing", file_path, *args)
  elsif RequireBench::INCLUDE_PATTERN.nil? || measure
    RequireBench.consume_with_timing(type, file_path, *args)
  else
    send("#{type}_without_timing", file_path, *args)
  end
end

#load(file, *args) ⇒ Object



148
149
150
# File 'lib/require_bench.rb', line 148

def load(file,  *args)
  _require_bench_consume_file('load', file, *args)
end

#load_without_timingObject



142
# File 'lib/require_bench.rb', line 142

alias load_without_timing load

#require(file) ⇒ Object



144
145
146
# File 'lib/require_bench.rb', line 144

def require(file)
  _require_bench_consume_file('require', file)
end

#require_without_timingObject



141
# File 'lib/require_bench.rb', line 141

alias require_without_timing require