1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
# frozen_string_literal: true
require 'set'
module Aws
# @api private
class EagerLoader
def initialize
@loaded = Set.new
end
# @return [Set<Module>]
attr_reader :loaded
# @param [Module] klass_or_module
# @return [self]
def load(klass_or_module)
@loaded << klass_or_module
klass_or_module.constants.each do |const_name|
path = klass_or_module.autoload?(const_name)
begin
require(path) if path
const = klass_or_module.const_get(const_name)
self.load(const) if Module === const && !@loaded.include?(const)
rescue LoadError
end
end
self
end
end
end
|