Sha256: 26f69d64e0d2ad8fe04c1a36dd07cf3a562da880bab8f494b573b99a703f3963

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

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

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

    alias nodes collection

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

    def any_of(name = :roots, **options, &block)
      NxtSchema::Node::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::Node::Schema::DEFAULT_TYPE, **options, &block)
      NxtSchema::Node::Schema.new(
        name: name,
        type: type,
        parent_node: nil,
        **options.merge(type_system: NxtSchema::Types::Params),
        &block
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nxt_schema-1.0.0 lib/nxt_schema/dsl.rb