Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Feature - Seahorse::Client::Configuration no longer generate real Ruby Struct at runtime.

3.265.0 (2026-11-06)
------------------

Expand Down
54 changes: 53 additions & 1 deletion gems/aws-sdk-core/lib/seahorse/client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,58 @@ def call(*args)
end
end

# @api private
class DynamicStruct
attr_reader :members

def initialize(members)
@members = members.map(&:to_sym).to_set
@attributes = {}
end

def [](name)
name = name.to_sym
unless @members.include?(name)
raise NameError, "No member #{name} in Struct"
end

@attributes[name]
end

def []=(name, value)
name = name.to_sym
unless @members.include?(name)
raise NameError, "No member #{name} in Struct"
end

@attributes[name] = value
end

private

alias_method :write_attribute, :[]=
alias_method :read_attribute, :[]

def method_missing(name, *args, **kwargs, &block)
if name.end_with?('=')
attr_name = name[0..-2].to_sym
if @members.include?(attr_name)
write_attribute(attr_name, *args, **kwargs, &block)
else
super
end
elsif @members.include?(name)
read_attribute(name, *args, **kwargs, &block)
else
super
end
end

def respond_to_missing?(name, include_private = false)
@members.include?(name) || (name.end_with?('=') && @members.include?(name[0..-2].to_sym)) || super
end
end

# @api private
def initialize
@defaults = Hash.new { |h,k| h[k] = Defaults.new }
Expand Down Expand Up @@ -156,7 +208,7 @@ def build!(options = {})
private

def empty_struct
Struct.new(*@defaults.keys.sort).new
DynamicStruct.new(@defaults.keys.sort)
end

def apply_options(struct, options)
Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/spec/seahorse/client/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Client
describe '#config' do

it 'returns a Configuration struct' do
expect(client.config).to be_kind_of(Struct)
expect(client.config).to be_kind_of(Configuration::DynamicStruct)
end

it 'contains the client api' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ module Client
it 'returns self so it can be chained' do
c = config.add_option(:name).add_option(:color)
expect(c).to be(config)
expect(c.build!.members).to eq([:color, :name])
expect(c.build!.members).to eq(Set[:color, :name])
end

end

describe '#build!' do

it 'returns a Struct' do
expect(config.add_option(:opt).build!).to be_kind_of(Struct)
expect(config.add_option(:opt).build!).to be_kind_of(Configuration::DynamicStruct)
end

it 'accepts a hash of options' do
Expand Down