Sha256: 2ba0d52326d513b25d9e81bb07d678614f824b79360ebc7d3a33b7b8e4a26db6

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module NxtSchema
  module Dsl
    DEFAULT_OPTIONS = { type_system: NxtSchema::Types }.freeze

    def collection(name = :root, type: NxtSchema::Template::Collection::DEFAULT_TYPE, **options, &block)
      NxtSchema::Template::Collection.new(
        name: name,
        type: type,
        parent_node: nil,
        **DEFAULT_OPTIONS.merge(options),
        &block
      )
    end

    alias nodes collection

    def schema(name = :roots, type: NxtSchema::Template::Schema::DEFAULT_TYPE, **options, &block)
      NxtSchema::Template::Schema.new(
        name: name,
        type: type,
        parent_node: nil,
        **DEFAULT_OPTIONS.merge(options),
        &block
      )
    end

    def any_of(name = :roots, **options, &block)
      NxtSchema::Template::AnyOf.new(
        name: name,
        parent_node: nil,
        **DEFAULT_OPTIONS.merge(options),
        &block
      )
    end

    # schema root with NxtSchema::Types::Params type system

    def params(name = :params, type: NxtSchema::Template::Schema::DEFAULT_TYPE, **options, &block)
      NxtSchema::Template::Schema.new(
        name: name,
        type: type,
        parent_node: nil,
        **options.merge(type_system: NxtSchema::Types::Params),
        &block
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nxt_schema-1.0.2 lib/nxt_schema/dsl.rb
nxt_schema-1.0.1 lib/nxt_schema/dsl.rb