157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/praxis/types/multipart_array.rb', line 157
def self.describe(shallow=true, example: nil)
type_name = Attributor.type_name(self)
hash = {
name: type_name.gsub(Attributor::MODULE_PREFIX_REGEX, ''),
family: self.family,
id: self.id
}
hash[:example] = example if example
hash[:part_name] = {type: name_type.describe(true)}
unless shallow
hash[:attributes] = {} if self.attributes.keys.any? { |name| name.kind_of? String}
hash[:pattern_attributes] = {} if self.attributes.keys.any? { |name| name.kind_of? Regexp}
if hash.key?(:attributes) || hash.key?(:pattern_attributes)
self.describe_attributes(shallow, example: example).each do |name, sub_hash|
case name
when String
hash[:attributes][name] = sub_hash
when Regexp
hash[:pattern_attributes][name.source] = sub_hash
end
end
else
hash[:part_payload] = {type: payload_type.describe(true)}
end
end
hash
end
|