Sha256: 0d186cca118b61b10b68c35a60a140a0667ff6370c62241c8d42aeb4241f7ff1

Contents?: true

Size: 712 Bytes

Versions: 3

Compression:

Stored size: 712 Bytes

Contents

require_relative 'entity'

module JSON
  module SchemaBuilder
    class Array < Entity
      register :array
      attribute :additional_items
      attribute :min_items
      attribute :max_items
      attribute :unique_items

      def items(*args, &block)
        opts = args.extract_options!
        schema[:items] = args.first
        schema[:items] ||= items_entity(opts, &block).as_json
        parent.reinitialize if parent
      end

      protected

      def items_entity(opts, &block)
        opts[:parent] = self
        if opts[:type]
          send opts.delete(:type), opts, &block
        else
          Entity.new(nil, opts, &block).tap &:merge_children!
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json-schema_builder-0.8.2 lib/json/schema_builder/array.rb
json-schema_builder-0.8.1 lib/json/schema_builder/array.rb
json-schema_builder-0.8.0 lib/json/schema_builder/array.rb