Sha256: e4e51eda4c314fca832490baf2d1133da4b4a0453b549a9eb5ccadd63ae2ee6f

Contents?: true

Size: 793 Bytes

Versions: 20

Compression:

Stored size: 793 Bytes

Contents

# frozen_string_literal: true

module Orthoses
  class Autoload
    module Hook
      def autoload(name, path)
        super
      end
    end

    def initialize(loader)
      @loader = loader
    end

    def call
      ::Module.prepend(Hook)

      autoload = CallTracer.new

      store = autoload.trace(Hook.instance_method(:autoload)) do
        @loader.call
      end

      autoload.captures.each do |capture|
        base_mod = capture.method.receiver
        name = capture.argument[:name]
        begin
          base_mod.const_get(name)
        rescue NameError, LoadError, ArgumentError => e
          Orthoses.logger.warn("[Orthoses::Autoload] raise `#{e.message} (#{e.class})` when try to unautoload `#{base_mod}::#{name}`")
        end
      end

      store
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
orthoses-1.17.0 lib/orthoses/autoload.rb
orthoses-1.16.0 lib/orthoses/autoload.rb
orthoses-1.15.0 lib/orthoses/autoload.rb
orthoses-1.14.0 lib/orthoses/autoload.rb
orthoses-1.13.0 lib/orthoses/autoload.rb
orthoses-1.12.0 lib/orthoses/autoload.rb
orthoses-1.11.0 lib/orthoses/autoload.rb
orthoses-1.10.0 lib/orthoses/autoload.rb
orthoses-1.9.0 lib/orthoses/autoload.rb
orthoses-1.8.0 lib/orthoses/autoload.rb
orthoses-1.7.0 lib/orthoses/autoload.rb
orthoses-1.6.0 lib/orthoses/autoload.rb
orthoses-1.5.0 lib/orthoses/autoload.rb
orthoses-1.4.0 lib/orthoses/autoload.rb
orthoses-1.3.0 lib/orthoses/autoload.rb
orthoses-1.2.0 lib/orthoses/autoload.rb
orthoses-1.1.0 lib/orthoses/autoload.rb
orthoses-1.0.0 lib/orthoses/autoload.rb
orthoses-0.11.0 lib/orthoses/autoload.rb
orthoses-0.10.0 lib/orthoses/autoload.rb