@@ -8,7 +8,6 @@ module Schema
88 # Document Utilities to help (de)construct given data as a document
99 module DocumentUtils
1010 class << self
11-
1211 # Used to transform untyped data
1312 def format ( data )
1413 return if data . nil?
@@ -26,6 +25,19 @@ def format(data)
2625 end
2726 end
2827
28+ def apply ( data , schema , type = nil , opts = { } )
29+ case resolve_shape ( schema )
30+ when Shapes ::StructureShape then apply_structure ( data , schema , type )
31+ when Shapes ::UnionShape then apply_union ( data , schema , type )
32+ when Shapes ::ListShape then apply_list ( data , schema )
33+ when Shapes ::MapShape then apply_map ( data , schema )
34+ when Shapes ::TimestampShape then apply_timestamp ( data , schema , opts )
35+ when Shapes ::BlobShape then Base64 . decode64 ( data )
36+ else data
37+ end
38+ end
39+
40+ # rubocop:disable Metrics/CyclomaticComplexity
2941 def extract ( data , schema , opts = { } )
3042 return if data . nil?
3143
@@ -39,18 +51,7 @@ def extract(data, schema, opts = {})
3951 else data
4052 end
4153 end
42-
43- def apply ( data , schema , type = nil , opts = { } )
44- case resolve_shape ( schema )
45- when Shapes ::StructureShape then apply_structure ( data , schema , type )
46- when Shapes ::UnionShape then apply_union ( data , schema , type )
47- when Shapes ::ListShape then apply_list ( data , schema )
48- when Shapes ::MapShape then apply_map ( data , schema )
49- when Shapes ::TimestampShape then apply_timestamp ( data , schema , opts )
50- when Shapes ::BlobShape then Base64 . decode64 ( data )
51- else data
52- end
53- end
54+ # rubocop:enable Metrics/CyclomaticComplexity
5455
5556 private
5657
@@ -78,6 +79,7 @@ def apply_timestamp(data, schema, opts)
7879 time ( data , trait )
7980 end
8081
82+ # rubocop:disable Metrics/AbcSize
8183 def apply_union ( data , schema , type )
8284 shape = resolve_shape ( schema )
8385 key , value = data . flatten
@@ -95,14 +97,14 @@ def apply_union(data, schema, type)
9597 shape . member_type ( :unknown ) . new ( key , value )
9698 end
9799 end
100+ # rubocop:enable Metrics/AbcSize
98101
99102 def json_name_member ( name , shape )
100103 shape . members . values . find do |v |
101104 v . traits [ 'smithy.api#jsonName' ] == name if v . traits . include? ( 'smithy.api#jsonName' )
102105 end
103106 end
104107
105-
106108 def apply_list ( data , schema )
107109 shape = resolve_shape ( schema )
108110 data . map do |v |
@@ -134,6 +136,7 @@ def extract_structure(data, schema, opts)
134136 end
135137 end
136138
139+ # rubocop:disable Metrics/AbcSize
137140 def extract_union ( data , schema , opts )
138141 h = { }
139142 shape = resolve_shape ( schema )
@@ -151,6 +154,7 @@ def extract_union(data, schema, opts)
151154 end
152155 h
153156 end
157+ # rubocop:enable Metrics/AbcSize
154158
155159 def extract_list ( data , schema )
156160 shape = resolve_shape ( schema )
@@ -175,6 +179,12 @@ def extract_timestamp(data, schema, opts)
175179 time ( data , trait )
176180 end
177181
182+ def member_name ( schema , key )
183+ return unless schema . name_by_member_name? ( key ) || schema . member? ( key . to_sym )
184+
185+ schema . name_by_member_name ( key ) || key . to_sym
186+ end
187+
178188 def resolve_shape ( schema )
179189 schema . is_a? ( Shapes ::MemberShape ) ? schema . shape : schema
180190 end
@@ -187,12 +197,6 @@ def resolve_member_name(member_shape, opts)
187197 end
188198 end
189199
190- def member_name ( schema , key )
191- return unless schema . name_by_member_name? ( key ) || schema . member? ( key . to_sym )
192-
193- schema . name_by_member_name ( key ) || key . to_sym
194- end
195-
196200 def resolve_timestamp_trait ( schema )
197201 if schema . is_a? ( Shapes ::MemberShape )
198202 schema . traits [ 'smithy.api#timestampFormat' ]
0 commit comments