Skip to content

Commit

Permalink
Aws.eager_autoload! now loads non-service utility classes.
Browse files Browse the repository at this point in the history
Fixes #833
  • Loading branch information
trevorrowe committed Jun 12, 2015
1 parent fa195fd commit 465695a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 15 additions & 7 deletions aws-sdk-core/lib/aws-sdk-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ module Response
# @api private
module Signers
autoload :Base, 'aws-sdk-core/signers/base'
autoload :Handler, 'aws-sdk-core/signers/handler'
autoload :S3, 'aws-sdk-core/signers/s3'
autoload :V2, 'aws-sdk-core/signers/v2'
autoload :V3, 'aws-sdk-core/signers/v3'
Expand Down Expand Up @@ -285,16 +284,25 @@ def eager_autoload!(options = {})
eager_loader = EagerLoader.new
eager_loader.load(JMESPath)
eager_loader.load(Seahorse)
(options[:services] || SERVICE_MODULE_NAMES).each do |svc_name|
begin
eager_loader.load(Aws.const_get(svc_name))
rescue NameError
raise ArgumentError, "invalid service Aws::#{svc_name}"
end
sub_modules(options).each do |module_or_class|
eager_loader.load(module_or_class)
end
eager_loader
end

def sub_modules(options = {})
constants = Aws.constants.map(&:to_s)
if options[:services]
constants -= SERVICE_MODULE_NAMES
constants += options[:services] || SERVICE_MODULE_NAMES
end
constants.inject([]) do |modules, const_name|
constant = Aws.const_get(const_name)
modules << constant if Module === constant
modules
end
end

# Yields to the given block for each service that has already been
# defined via {add_service}. Also yields to the given block for
# each new service added after the callback is registered.
Expand Down
5 changes: 5 additions & 0 deletions aws-sdk-core/spec/aws_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,10 @@ module Aws
expect(eager_loader.loaded).not_to include(Aws::EC2)
end

it 'loads non-service modules' do
eager_loader = Aws.eager_autoload!
expect(eager_loader.loaded).to include(Aws::Xml)
end

end
end

0 comments on commit 465695a

Please sign in to comment.