Sha256: eb186c58f2320ab5f678f08f9a143497f672e06c8ba0f759837dff928b317f92

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

module Fakeit
  module Openapi
    module Example
      MAX_SIZE = 50

      def array_example(use_example)
        size = retries = uniqueItems ? min_array : Faker::Number.between(min_array, max_array)

        generate_items(size, retries, use_example)
      end

      private

      def generate_items(size, retries, use_example)
        result = []

        loop do
          item = items.to_example(use_example)

          if need_retry?(item, result, retries)
            retries -= 1
            next
          end

          break if (result << item).size >= size
        end

        result
      end

      def need_retry?(item, result, retries)
        uniqueItems && result.include?(item) && retries.positive?
      end

      def min_array
        minItems || 1
      end

      def max_array
        maxItems || MAX_SIZE
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fakeit-0.1.3 lib/fakeit/openapi/example/array_example.rb