Sha256: 28e4686db168cea3dc9570661b941338261f5920a31b03fa2736dce1c87b79ec

Contents?: true

Size: 851 Bytes

Versions: 5

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

require 'jimmy/declaration'

module Jimmy
  # The +Macros+ module includes methods that can be called directly on the
  # +Jimmy+ module for quickly making common types of schemas.
  module Macros
    include Declaration

    # Make a new schema. Shortcut for +Schema.new+.
    # @yieldparam schema [Schema] The new schema
    # @return [Schema] The new schema.
    def schema(&block)
      Schema.new &block
    end

    # Make a schema that never validates.
    # @return [Schema] The new schema.
    def nothing
      schema.nothing
    end

    # Make a schema that references another schema by URI.
    # @param [String, URI, Json::URI] uri
    # @return [Schema] The new schema.
    def ref(uri)
      schema.ref uri
    end

    private

    def get(*args, &block)
      {}.fetch(*args, &block)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jimmy-2.1.0 lib/jimmy/macros.rb
jimmy-2.0.3 lib/jimmy/macros.rb
jimmy-2.0.2 lib/jimmy/macros.rb
jimmy-2.0.1 lib/jimmy/macros.rb
jimmy-2.0.0 lib/jimmy/macros.rb