| 1 |
require 'set' |
|---|
| 2 |
require File.dirname(__FILE__) + '/core_ext/module/attribute_accessors' |
|---|
| 3 |
require File.dirname(__FILE__) + '/core_ext/load_error' |
|---|
| 4 |
require File.dirname(__FILE__) + '/core_ext/kernel' |
|---|
| 5 |
|
|---|
| 6 |
module Dependencies |
|---|
| 7 |
extend self |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
mattr_accessor :warnings_on_first_load |
|---|
| 11 |
self.warnings_on_first_load = false |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
mattr_accessor :history |
|---|
| 15 |
self.history = Set.new |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
mattr_accessor :loaded |
|---|
| 19 |
self.loaded = Set.new |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
mattr_accessor :mechanism |
|---|
| 23 |
self.mechanism = :load |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
mattr_accessor :load_paths |
|---|
| 29 |
self.load_paths = [] |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
mattr_accessor :load_once_paths |
|---|
| 34 |
self.load_once_paths = [] |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
mattr_accessor :autoloaded_constants |
|---|
| 39 |
self.autoloaded_constants = [] |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
mattr_accessor :explicitly_unloadable_constants |
|---|
| 44 |
self.explicitly_unloadable_constants = [] |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
mattr_accessor :log_activity |
|---|
| 48 |
self.log_activity = false |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
mattr_accessor :constant_watch_stack |
|---|
| 52 |
self.constant_watch_stack = [] |
|---|
| 53 |
|
|---|
| 54 |
def load? |
|---|
| 55 |
mechanism == :load |
|---|
| 56 |
end |
|---|
| 57 |
|
|---|
| 58 |
def depend_on(file_name, swallow_load_errors = false) |
|---|
| 59 |
path = search_for_file(file_name) |
|---|
| 60 |
require_or_load(path || file_name) |
|---|
| 61 |
rescue LoadError |
|---|
| 62 |
raise unless swallow_load_errors |
|---|
| 63 |
end |
|---|
| 64 |
|
|---|
| 65 |
def associate_with(file_name) |
|---|
| 66 |
depend_on(file_name, true) |
|---|
| 67 |
end |
|---|
| 68 |
|
|---|
| 69 |
def clear |
|---|
| 70 |
log_call |
|---|
| 71 |
loaded.clear |
|---|
| 72 |
remove_unloadable_constants! |
|---|
| 73 |
end |
|---|
| 74 |
|
|---|
| 75 |
def require_or_load(file_name, const_path = nil) |
|---|
| 76 |
log_call file_name, const_path |
|---|
| 77 |
file_name = $1 if file_name =~ /^(.*)\.rb$/ |
|---|
| 78 |
expanded = File.expand_path(file_name) |
|---|
| 79 |
return if loaded.include?(expanded) |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
loaded << expanded |
|---|
| 84 |
|
|---|
| 85 |
if load? |
|---|
| 86 |
log "loading #{file_name}" |
|---|
| 87 |
begin |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
load_args = ["#{file_name}.rb"] |
|---|
| 91 |
load_args << const_path unless const_path.nil? |
|---|
| 92 |
|
|---|
| 93 |
if !warnings_on_first_load or history.include?(expanded) |
|---|
| 94 |
result = load_file(*load_args) |
|---|
| 95 |
else |
|---|
| 96 |
enable_warnings { result = load_file(*load_args) } |
|---|
| 97 |
end |
|---|
| 98 |
rescue Exception |
|---|
| 99 |
loaded.delete expanded |
|---|
| 100 |
raise |
|---|
| 101 |
end |
|---|
| 102 |
else |
|---|
| 103 |
log "requiring #{file_name}" |
|---|
| 104 |
result = require file_name |
|---|
| 105 |
end |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
history << expanded |
|---|
| 109 |
return result |
|---|
| 110 |
end |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
def qualified_const_defined?(path) |
|---|
| 114 |
raise NameError, "#{path.inspect} is not a valid constant name!" unless |
|---|
| 115 |
/^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ path |
|---|
| 116 |
|
|---|
| 117 |
names = path.split('::') |
|---|
| 118 |
names.shift if names.first.empty? |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
names.inject(Object) do |mod, name| |
|---|
| 123 |
return false unless mod.const_defined? name |
|---|
| 124 |
mod.const_get name |
|---|
| 125 |
end |
|---|
| 126 |
return true |
|---|
| 127 |
end |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
def loadable_constants_for_path(path, bases = load_paths) |
|---|
| 133 |
path = $1 if path =~ /\A(.*)\.rb\Z/ |
|---|
| 134 |
expanded_path = File.expand_path(path) |
|---|
| 135 |
|
|---|
| 136 |
bases.collect do |root| |
|---|
| 137 |
expanded_root = File.expand_path(root) |
|---|
| 138 |
next unless %r{\A |
|---|
| 139 |
|
|---|
| 140 |
nesting = expanded_path[(expanded_root.size)..-1] |
|---|
| 141 |
nesting = nesting[1..-1] if nesting && nesting[0] == ?/ |
|---|
| 142 |
next if nesting.blank? |
|---|
| 143 |
|
|---|
| 144 |
[ |
|---|
| 145 |
nesting.camelize, |
|---|
| 146 |
|
|---|
| 147 |
('ApplicationController' if nesting == 'application') |
|---|
| 148 |
] |
|---|
| 149 |
end.flatten.compact.uniq |
|---|
| 150 |
end |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
def search_for_file(path_suffix) |
|---|
| 154 |
path_suffix = path_suffix + '.rb' unless path_suffix.ends_with? '.rb' |
|---|
| 155 |
load_paths.each do |root| |
|---|
| 156 |
path = File.join(root, path_suffix) |
|---|
| 157 |
return path if File.file? path |
|---|
| 158 |
end |
|---|
| 159 |
nil |
|---|
| 160 |
end |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
def autoloadable_module?(path_suffix) |
|---|
| 165 |
load_paths.each do |load_path| |
|---|
| 166 |
return load_path if File.directory? File.join(load_path, path_suffix) |
|---|
| 167 |
end |
|---|
| 168 |
nil |
|---|
| 169 |
end |
|---|
| 170 |
|
|---|
| 171 |
def load_once_path?(path) |
|---|
| 172 |
load_once_paths.any? { |base| path.starts_with? base } |
|---|
| 173 |
end |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
def autoload_module!(into, const_name, qualified_name, path_suffix) |
|---|
| 181 |
return nil unless base_path = autoloadable_module?(path_suffix) |
|---|
| 182 |
mod = Module.new |
|---|
| 183 |
into.const_set const_name, mod |
|---|
| 184 |
autoloaded_constants << qualified_name unless load_once_paths.include?(base_path) |
|---|
| 185 |
return mod |
|---|
| 186 |
end |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
def load_file(path, const_paths = loadable_constants_for_path(path)) |
|---|
| 197 |
log_call path, const_paths |
|---|
| 198 |
const_paths = [const_paths].compact unless const_paths.is_a? Array |
|---|
| 199 |
parent_paths = const_paths.collect { |const_path| /(.*)::[^:]+\Z/ =~ const_path ? $1 : :Object } |
|---|
| 200 |
|
|---|
| 201 |
result = nil |
|---|
| 202 |
newly_defined_paths = new_constants_in(*parent_paths) do |
|---|
| 203 |
result = load_without_new_constant_marking path |
|---|
| 204 |
end |
|---|
| 205 |
|
|---|
| 206 |
autoloaded_constants.concat newly_defined_paths unless load_once_path?(path) |
|---|
| 207 |
autoloaded_constants.uniq! |
|---|
| 208 |
log "loading #{path} defined #{newly_defined_paths * ', '}" unless newly_defined_paths.empty? |
|---|
| 209 |
return result |
|---|
| 210 |
end |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
def qualified_name_for(mod, name) |
|---|
| 214 |
mod_name = to_constant_name mod |
|---|
| 215 |
(%w(Object Kernel).include? mod_name) ? name.to_s : "#{mod_name}::#{name}" |
|---|
| 216 |
end |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
def load_missing_constant(from_mod, const_name) |
|---|
| 222 |
log_call from_mod, const_name |
|---|
| 223 |
if from_mod == Kernel |
|---|
| 224 |
if ::Object.const_defined?(const_name) |
|---|
| 225 |
log "Returning Object::#{const_name} for Kernel::#{const_name}" |
|---|
| 226 |
return ::Object.const_get(const_name) |
|---|
| 227 |
else |
|---|
| 228 |
log "Substituting Object for Kernel" |
|---|
| 229 |
from_mod = Object |
|---|
| 230 |
end |
|---|
| 231 |
end |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
from_mod = Object if from_mod.name.empty? |
|---|
| 235 |
|
|---|
| 236 |
unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id |
|---|
| 237 |
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!" |
|---|
| 238 |
end |
|---|
| 239 |
|
|---|
| 240 |
raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name) |
|---|
| 241 |
|
|---|
| 242 |
qualified_name = qualified_name_for from_mod, const_name |
|---|
| 243 |
path_suffix = qualified_name.underscore |
|---|
| 244 |
name_error = NameError.new("uninitialized constant #{qualified_name}") |
|---|
| 245 |
|
|---|
| 246 |
file_path = search_for_file(path_suffix) |
|---|
| 247 |
if file_path && ! loaded.include?(File.expand_path(file_path)) |
|---|
| 248 |
require_or_load file_path |
|---|
| 249 |
raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless from_mod.const_defined?(const_name) |
|---|
| 250 |
return from_mod.const_get(const_name) |
|---|
| 251 |
elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix) |
|---|
| 252 |
return mod |
|---|
| 253 |
elsif (parent = from_mod.parent) && parent != from_mod && |
|---|
| 254 |
! from_mod.parents.any? { |p| p.const_defined?(const_name) } |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
begin |
|---|
| 260 |
return parent.const_missing(const_name) |
|---|
| 261 |
rescue NameError => e |
|---|
| 262 |
raise unless e.missing_name? qualified_name_for(parent, const_name) |
|---|
| 263 |
raise name_error |
|---|
| 264 |
end |
|---|
| 265 |
else |
|---|
| 266 |
raise name_error |
|---|
| 267 |
end |
|---|
| 268 |
end |
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
def remove_unloadable_constants! |
|---|
| 273 |
autoloaded_constants.each { |const| remove_constant const } |
|---|
| 274 |
autoloaded_constants.clear |
|---|
| 275 |
explicitly_unloadable_constants.each { |const| remove_constant const } |
|---|
| 276 |
end |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
def autoloaded?(desc) |
|---|
| 280 |
|
|---|
| 281 |
return false if desc.is_a?(Module) && desc.name.blank? |
|---|
| 282 |
name = to_constant_name desc |
|---|
| 283 |
return false unless qualified_const_defined? name |
|---|
| 284 |
return autoloaded_constants.include?(name) |
|---|
| 285 |
end |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
def will_unload?(const_desc) |
|---|
| 289 |
autoloaded?(desc) || |
|---|
| 290 |
explicitly_unloadable_constants.include?(to_constant_name(const_desc)) |
|---|
| 291 |
end |
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
def mark_for_unload(const_desc) |
|---|
| 296 |
name = to_constant_name const_desc |
|---|
| 297 |
if explicitly_unloadable_constants.include? name |
|---|
| 298 |
return false |
|---|
| 299 |
else |
|---|
| 300 |
explicitly_unloadable_constants << name |
|---|
| 301 |
return true |
|---|
| 302 |
end |
|---|
| 303 |
end |
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
def new_constants_in(*descs) |
|---|
| 314 |
log_call(*descs) |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
watch_frames = descs.collect do |desc| |
|---|
| 319 |
if desc.is_a? Module |
|---|
| 320 |
mod_name = desc.name |
|---|
| 321 |
initial_constants = desc.local_constants |
|---|
| 322 |
elsif desc.is_a?(String) || desc.is_a?(Symbol) |
|---|
| 323 |
mod_name = desc.to_s |
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
initial_constants = if qualified_const_defined?(mod_name) |
|---|
| 327 |
mod_name.constantize.local_constants |
|---|
| 328 |
else |
|---|
| 329 |
[] |
|---|
| 330 |
end |
|---|
| 331 |
else |
|---|
| 332 |
raise Argument, "#{desc.inspect} does not describe a module!" |
|---|
| 333 |
end |
|---|
| 334 |
|
|---|
| 335 |
[mod_name, initial_constants] |
|---|
| 336 |
end |
|---|
| 337 |
|
|---|
| 338 |
constant_watch_stack.concat watch_frames |
|---|
| 339 |
|
|---|
| 340 |
aborting = true |
|---|
| 341 |
begin |
|---|
| 342 |
yield |
|---|
| 343 |
aborting = false |
|---|
| 344 |
ensure |
|---|
| 345 |
|
|---|
| 346 |
new_constants = watch_frames.collect do |mod_name, prior_constants| |
|---|
| 347 |
|
|---|
| 348 |
next [] unless qualified_const_defined?(mod_name) |
|---|
| 349 |
|
|---|
| 350 |
mod = mod_name.constantize |
|---|
| 351 |
next [] unless mod.is_a? Module |
|---|
| 352 |
new_constants = mod.local_constants - prior_constants |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
constant_watch_stack.each do |frame_name, constants| |
|---|
| 356 |
constants.concat new_constants if frame_name == mod_name |
|---|
| 357 |
end |
|---|
| 358 |
|
|---|
| 359 |
new_constants.collect do |suffix| |
|---|
| 360 |
mod_name == "Object" ? suffix : "#{mod_name}::#{suffix}" |
|---|
| 361 |
end |
|---|
| 362 |
end.flatten |
|---|
| 363 |
|
|---|
| 364 |
log "New constants: #{new_constants * ', '}" |
|---|
| 365 |
|
|---|
| 366 |
if aborting |
|---|
| 367 |
log "Error during loading, removing partially loaded constants " |
|---|
| 368 |
new_constants.each { |name| remove_constant name } |
|---|
| 369 |
new_constants.clear |
|---|
| 370 |
end |
|---|
| 371 |
end |
|---|
| 372 |
|
|---|
| 373 |
return new_constants |
|---|
| 374 |
ensure |
|---|
| 375 |
|
|---|
| 376 |
if defined?(watch_frames) && ! watch_frames.empty? |
|---|
| 377 |
frame_ids = watch_frames.collect(&:object_id) |
|---|
| 378 |
constant_watch_stack.delete_if do |watch_frame| |
|---|
| 379 |
frame_ids.include? watch_frame.object_id |
|---|
| 380 |
end |
|---|
| 381 |
end |
|---|
| 382 |
end |
|---|
| 383 |
|
|---|
| 384 |
class LoadingModule |
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
def self.root(*args) |
|---|
| 388 |
if defined?(RAILS_DEFAULT_LOGGER) |
|---|
| 389 |
RAILS_DEFAULT_LOGGER.warn "Your environment.rb uses the old syntax, it may not continue to work in future releases." |
|---|
| 390 |
RAILS_DEFAULT_LOGGER.warn "For upgrade instructions please see: http://manuals.rubyonrails.com/read/book/19" |
|---|
| 391 |
end |
|---|
| 392 |
end |
|---|
| 393 |
end |
|---|
| 394 |
|
|---|
| 395 |
protected |
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
def to_constant_name(desc) |
|---|
| 400 |
name = case desc |
|---|
| 401 |
when String then desc.starts_with?('::') ? desc[2..-1] : desc |
|---|
| 402 |
when Symbol then desc.to_s |
|---|
| 403 |
when Module |
|---|
| 404 |
raise ArgumentError, "Anonymous modules have no name to be referenced by" if desc.name.blank? |
|---|
| 405 |
desc.name |
|---|
| 406 |
else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}" |
|---|
| 407 |
end |
|---|
| 408 |
end |
|---|
| 409 |
|
|---|
| 410 |
def remove_constant(const) |
|---|
| 411 |
return false unless qualified_const_defined? const |
|---|
| 412 |
|
|---|
| 413 |
const = $1 if /\A::(.*)\Z/ =~ const.to_s |
|---|
| 414 |
names = const.split('::') |
|---|
| 415 |
if names.size == 1 |
|---|
| 416 |
parent = Object |
|---|
| 417 |
else |
|---|
| 418 |
parent = (names[0..-2] * '::').constantize |
|---|
| 419 |
end |
|---|
| 420 |
|
|---|
| 421 |
log "removing constant #{const}" |
|---|
| 422 |
parent.send :remove_const, names.last |
|---|
| 423 |
return true |
|---|
| 424 |
end |
|---|
| 425 |
|
|---|
| 426 |
def log_call(*args) |
|---|
| 427 |
arg_str = args.collect(&:inspect) * ', ' |
|---|
| 428 |
/in `([a-z_\?\!]+)'/ =~ caller(1).first |
|---|
| 429 |
selector = $1 || '<unknown>' |
|---|
| 430 |
log "called #{selector}(#{arg_str})" |
|---|
| 431 |
end |
|---|
| 432 |
|
|---|
| 433 |
def log(msg) |
|---|
| 434 |
if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity |
|---|
| 435 |
RAILS_DEFAULT_LOGGER.debug "Dependencies: #{msg}" |
|---|
| 436 |
end |
|---|
| 437 |
end |
|---|
| 438 |
|
|---|
| 439 |
end |
|---|
| 440 |
|
|---|
| 441 |
Object.send(:define_method, :require_or_load) { |file_name| Dependencies.require_or_load(file_name) } unless Object.respond_to?(:require_or_load) |
|---|
| 442 |
Object.send(:define_method, :require_dependency) { |file_name| Dependencies.depend_on(file_name) } unless Object.respond_to?(:require_dependency) |
|---|
| 443 |
Object.send(:define_method, :require_association) { |file_name| Dependencies.associate_with(file_name) } unless Object.respond_to?(:require_association) |
|---|
| 444 |
|
|---|
| 445 |
class Module |
|---|
| 446 |
|
|---|
| 447 |
alias :rails_original_const_missing :const_missing |
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
def const_missing(class_id) |
|---|
| 452 |
Dependencies.load_missing_constant self, class_id |
|---|
| 453 |
end |
|---|
| 454 |
|
|---|
| 455 |
def unloadable(const_desc = self) |
|---|
| 456 |
super(const_desc) |
|---|
| 457 |
end |
|---|
| 458 |
|
|---|
| 459 |
end |
|---|
| 460 |
|
|---|
| 461 |
class Class |
|---|
| 462 |
def const_missing(class_id) |
|---|
| 463 |
if [Object, Kernel].include?(self) || parent == self |
|---|
| 464 |
super |
|---|
| 465 |
else |
|---|
| 466 |
begin |
|---|
| 467 |
begin |
|---|
| 468 |
Dependencies.load_missing_constant self, class_id |
|---|
| 469 |
rescue NameError |
|---|
| 470 |
parent.send :const_missing, class_id |
|---|
| 471 |
end |
|---|
| 472 |
rescue NameError => e |
|---|
| 473 |
|
|---|
| 474 |
parent_qualified_name = Dependencies.qualified_name_for parent, class_id |
|---|
| 475 |
raise unless e.missing_name? parent_qualified_name |
|---|
| 476 |
qualified_name = Dependencies.qualified_name_for self, class_id |
|---|
| 477 |
raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) |
|---|
| 478 |
end |
|---|
| 479 |
end |
|---|
| 480 |
end |
|---|
| 481 |
end |
|---|
| 482 |
|
|---|
| 483 |
class Object |
|---|
| 484 |
|
|---|
| 485 |
alias_method :load_without_new_constant_marking, :load |
|---|
| 486 |
|
|---|
| 487 |
def load(file, *extras) |
|---|
| 488 |
Dependencies.new_constants_in(Object) { super(file, *extras) } |
|---|
| 489 |
rescue Exception => exception |
|---|
| 490 |
exception.blame_file! file |
|---|
| 491 |
raise |
|---|
| 492 |
end |
|---|
| 493 |
|
|---|
| 494 |
def require(file, *extras) |
|---|
| 495 |
Dependencies.new_constants_in(Object) { super(file, *extras) } |
|---|
| 496 |
rescue Exception => exception |
|---|
| 497 |
exception.blame_file! file |
|---|
| 498 |
raise |
|---|
| 499 |
end |
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
def unloadable(const_desc) |
|---|
| 515 |
Dependencies.mark_for_unload const_desc |
|---|
| 516 |
end |
|---|
| 517 |
|
|---|
| 518 |
end |
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
class Exception |
|---|
| 522 |
def blame_file!(file) |
|---|
| 523 |
(@blamed_files ||= []).unshift file |
|---|
| 524 |
end |
|---|
| 525 |
|
|---|
| 526 |
def blamed_files |
|---|
| 527 |
@blamed_files ||= [] |
|---|
| 528 |
end |
|---|
| 529 |
|
|---|
| 530 |
def describe_blame |
|---|
| 531 |
return nil if blamed_files.empty? |
|---|
| 532 |
"This error occurred while loading the following files:\n #{blamed_files.join "\n "}" |
|---|
| 533 |
end |
|---|
| 534 |
|
|---|
| 535 |
def copy_blame!(exc) |
|---|
| 536 |
@blamed_files = exc.blamed_files.clone |
|---|
| 537 |
self |
|---|
| 538 |
end |
|---|
| 539 |
end |
|---|