223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/attributor/types/hash.rb', line 223
def self.example(context = nil, **values)
return new if key_type == Object && value_type == Object && keys.empty?
context ||= ["#{Hash}-#{rand(10_000_000)}"]
context = Array(context)
if keys.any?
result = new
result.extend(ExampleMixin)
result.lazy_attributes = example_contents(context, result, **values)
else
hash = ::Hash.new
(rand(3) + 1).times do |i|
example_key = key_type.example(context + ["at(#{i})"])
subcontext = context + ["at(#{example_key})"]
hash[example_key] = value_type.example(subcontext)
end
result = new(hash)
end
result
end
|