forked from aws/aws-sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomizer.rb
75 lines (61 loc) · 2 KB
/
customizer.rb
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
module Aws
module Api
class Customizer
# @api private
def initialize(client_class)
@client_class = client_class
@api = client_class.api
end
# @return [Class<Seahorse::Client::Base>]
attr_reader :client_class
# @return [Seahorse::Model::Api]
attr_reader :api
# @api private
def apply(&customizations)
instance_eval(&customizations)
end
# @param [String, Class<Seahorse::Client::Plugin>] plugin
def add_plugin(plugin)
@client_class.add_plugin(plugin)
end
# @param [String, Class<Seahorse::Client::Plugin>] plugin
def remove_plugin(plugin)
@client_class.remove_plugin(plugin)
end
def metadata(key, value)
@client_class.api.definition['metadata'][key] = value
end
def add_shape(shape_name, definition)
@client_class.api.definition['shapes'][shape_name] = definition
end
def reshape(shape_name, modifications)
shape = @client_class.api.definition['shapes'][shape_name]
shape = deep_merge(shape, modifications)
@client_class.api.definition['shapes'][shape_name] = shape
end
def reshape_members(member_regex, modifications)
if member_regex.is_a?(String)
member_regex = /^#{member_regex}$/
end
@client_class.api.definition['shapes'].each do |shape_name, shape|
if shape['members']
shape['members'].each do |member_name, member_ref|
if member_name.match(member_regex)
shape['members'][member_name] = deep_merge(member_ref, modifications)
end
end
end
end
end
def each_operation(&block)
@client_class.api.definition['operations'].each(&block)
end
private
def deep_merge(first_hash, other_hash)
first_hash.merge(other_hash) do |key, old, new|
Hash === old && Hash === new ? deep_merge(old, new) : new
end
end
end
end
end