-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduces autoloading strategy for service gems #3105
Changes from 17 commits
f3dbfe1
82d6b54
f16cc3d
44fd76d
796356c
2b8a515
3702029
11139ba
8e7d8db
b46bc2c
4b2e6a4
3a756c6
aea96fe
2ea74a4
df22114
242e7e1
7b95851
7a7b372
2cb5937
f1fe00d
abbc1d8
8057c80
5690ebb
790ddd1
10ecce8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ def initialize(options) | |
paginators: options.fetch(:paginators) | ||
) | ||
@custom = options.fetch(:custom) | ||
@name = @module_name.split('::').last.downcase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this gem name? Why do the other classes have a method and this not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah good call - will refactor it to follow pattern of other modules. |
||
end | ||
|
||
# @return [String] | ||
|
@@ -53,6 +54,16 @@ def documentation? | |
actions? || associations? | ||
end | ||
|
||
# @return [Boolean] | ||
def customization_file_exists? | ||
File.exist?(File.join(__dir__, "../../../../../gems/aws-sdk-#{@name}/lib/aws-sdk-#{@name}/customizations/resource.rb")) | ||
end | ||
|
||
# @return [String] | ||
def customization_file_path | ||
"aws-sdk-#{@name}/customizations/resource" | ||
end | ||
|
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ class ServiceModule < View | |
def initialize(options) | ||
@service = options.fetch(:service) | ||
@prefix = options.fetch(:prefix) | ||
@codegenerated_plugins = options.fetch(:codegenerated_plugins) | ||
@codegenerated_plugins = options.fetch(:codegenerated_plugins) || [] | ||
end | ||
|
||
# @return [String|nil] | ||
|
@@ -61,15 +61,13 @@ def require_core_guard? | |
end | ||
|
||
# @return [Array<String>] | ||
def relative_requires | ||
def autoloads | ||
paths = Set.new | ||
paths << "#{@prefix}/types" | ||
paths << "#{@prefix}/client_api" | ||
|
||
# these must be required before the client | ||
if @codegenerated_plugins | ||
paths += @codegenerated_plugins.map { | p| p.path } | ||
end | ||
paths += @codegenerated_plugins.map { |p| p.path } | ||
|
||
paths << "#{@prefix}/client" | ||
paths << "#{@prefix}/errors" | ||
|
@@ -94,13 +92,32 @@ def relative_requires | |
end | ||
paths << "#{@prefix}/customizations" | ||
if @service.api['metadata']['protocolSettings'] && | ||
@service.api['metadata']['protocolSettings']['h2'] == 'eventstream' | ||
@service.api['metadata']['protocolSettings']['h2'] == 'eventstream' | ||
paths << "#{@prefix}/async_client" | ||
paths << "#{@prefix}/event_streams" | ||
elsif eventstream_shape? | ||
paths << "#{@prefix}/event_streams" | ||
end | ||
paths.to_a | ||
|
||
plugin_paths = @codegenerated_plugins.map { |p| [p.path, p] }.to_h || {} | ||
|
||
results = paths.map do |path| | ||
class_name = File.basename(path).split('.').first.split('_').map(&:capitalize).join | ||
alextwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Handle the Db -> DB case for AWS database-related constants | ||
class_name = class_name.gsub(/Db(?=[A-Z]|$)/, 'DB') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many inflections that need to be handled.. I don't like this as a one-off. Consider somehow using the inflections from the underscore method and verify nothing bad happens? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've actually completely changed this method so that it should not need to do this class name inference and hopefully made it more readable. |
||
{ | ||
file_path: path, | ||
class_name: class_name, | ||
is_plugin: plugin_paths.key?(path) | ||
} | ||
end | ||
|
||
results.reject { |r| r[:class_name].include?('Customizations') } | ||
end | ||
|
||
def service_identifier | ||
@prefix | ||
end | ||
|
||
def example_var_name | ||
|
@@ -109,6 +126,7 @@ def example_var_name | |
|
||
def example_operation_name | ||
raise "no operations found for the service" if @service.api['operations'].empty? | ||
|
||
alextwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
underscore(@service.api['operations'].keys.first) | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
# utility classes | ||
require 'aws-sdk-cloudfront/signer' | ||
require 'aws-sdk-cloudfront/url_signer' | ||
require 'aws-sdk-cloudfront/cookie_signer' | ||
module Aws | ||
module CloudFront | ||
autoload :Signer, 'aws-sdk-cloudfront/signer' | ||
autoload :UrlSigner, 'aws-sdk-cloudfront/url_signer' | ||
autoload :CookieSigner, 'aws-sdk-cloudfront/cookie_signer' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'spec_helper' | ||
require 'aws-sdk-cloudfront/customizations' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all spec files need to require customizations now? Could instead a generated spec helper (or somehow the shared one) do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was legacy of some other issues that have been fixed. Removed from here. |
||
|
||
module Aws | ||
module CloudFront | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'aws-sdk-cognitoidentity/customizations/cognito_identity_credentials' | ||
module Aws | ||
module CognitoIdentity | ||
autoload :CognitoIdentityCredentials, 'aws-sdk-cognitoidentity/customizations/cognito_identity_credentials' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
Unreleased Changes | ||
------------------ | ||
|
||
* Feature - Use autoloading at the service level to load service clients and resources. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all service gems need to be bumped to use this new version of core? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No -I don't think they need to. New service gems can still use the old core without issue (and vice versa). |
||
|
||
3.205.0 (2024-09-11) | ||
------------------ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'aws-defaults/default_configuration' | ||
module Aws | ||
autoload :DefaultsModeConfiguration, 'aws-defaults/default_configuration' | ||
autoload :DefaultsModeConfigResolver, 'aws-defaults/defaults_mode_config_resolver' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation of this can probably call customization_file_path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaned that up in all views + created a helper for the gem lib path.