Sha256: ae6157934e01e3eb960a6dff25cfafaa3e717a3caa53b2ed633f9fa1d91a9b59

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

# We need to override autoload, because MRI has special behaviors associated with it
# that we can't reuse, hence we need to do workarounds.
#
# Basically, when trying to use a constant set to be autoloaded in an optionnal way, like:
#   * module A; ...; end
#   * A ||= 1
# When autoloading the file, the above won't work and will raise a "uninitialized constant A"
# because ruby doesn't understand that custom require is currently requiring the correct file.
#
# Our solution is to track autoloads ourself, and when requiring a path that has autoloads,
# we remove the autoloads from the constants first.

require 'binding_of_caller'

class << Kernel
  alias_method :autoload_without_coverage, :autoload
  def autoload(name, path)
    mod = binding.of_caller(1).eval('Module.nesting').first || Object
    DeepCover.autoload_tracker.add(mod, name, path)
    mod.autoload_without_coverage(name, path)
  end
end

module Kernel
  alias_method :autoload_without_coverage, :autoload
  def autoload(name, path)
    mod = binding.of_caller(1).eval('Module.nesting').first || Object
    DeepCover.autoload_tracker.add(mod, name, path)
    mod.autoload_without_coverage(name, path)
  end
end


class Module
  alias_method :autoload_without_coverage, :autoload
  def autoload(name, path)
    DeepCover.autoload_tracker.add(self, name, path)
    autoload_without_coverage(name, path)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
deep-cover-0.1.9 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.8 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.7 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.6 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.5 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.4 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.3 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.2 lib/deep_cover/core_ext/autoload_overrides.rb
deep-cover-0.1.1 lib/deep_cover/core_ext/autoload_overrides.rb