Sha256: a92cd67daa8ab45dcd1a0b2e95c862270b8fba44b1f520be8d51845e6a89f2f0
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
module Fakeit module Openapi module Example FORMAT_HANDLERS = { 'uri' => -> { Faker::Internet.url }, 'uuid' => -> { SecureRandom.uuid }, 'email' => -> { Faker::Internet.email }, 'date' => -> { Faker::Date.backward(100).iso8601 }, 'date-time' => -> { Faker::Time.backward(100).iso8601 } }.freeze def string_example if enum then enum.to_a.sample elsif pattern then Faker::Base.regexify(pattern) elsif format then string_format elsif minLength || maxLength then string_with_length else Faker::Book.title end end private def string_with_length Faker::Internet.user_name(min_string_length..max_string_length) end def min_string_length minLength || 0 end def max_string_length maxLength || min_string_length + 10 end def string_format (FORMAT_HANDLERS[format] || method(:unknown_format))[] end def unknown_format Fakeit::Logger.warn("Unknown string format: #{format}") 'Unknown string format' end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fakeit-0.1.3 | lib/fakeit/openapi/example/string_example.rb |
fakeit-0.1.2 | lib/fakeit/openapi/example/string_example.rb |