448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
# File 'lib/attributor/types/hash.rb', line 448
def self.describe(shallow = false, example: nil)
hash = super(shallow)
hash[:key] = { type: key_type.describe(true) } if key_type
if keys.any?
if ( !shallow || self.name == nil)
required_names_from_attr = []
hash[:attributes] = self.keys.each_with_object({}) do |(sub_name, sub_attribute), sub_attributes|
required_names_from_attr << sub_name if sub_attribute.options[:required] == true
sub_example = example.get(sub_name) if example
sub_attributes[sub_name] = sub_attribute.describe(true, example: sub_example)
end
hash[:requirements] = requirements.each_with_object([]) do |req, list|
described_req = req.describe(shallow)
if described_req[:type] == :all
described_req[:attributes] |= required_names_from_attr
required_names_from_attr = []
end
list << described_req
end
unless required_names_from_attr.empty?
hash[:requirements] << {type: :all, attributes: required_names_from_attr }
end
end
else
hash[:value] = { type: value_type.describe(true) }
hash[:example] = example if example
hash[:attributes] = {}
end
hash
end
|