Sha256: 07c49c23a2887a8cb2df493056e49aa470f6ca18444edd36937a43f98328f988

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require_relative 'property'
require_relative 'builders/object_builder'

module EasyTalk
  # The Builder class is responsible for building a schema for a class.
  class Builder
    extend T::Sig

    sig { params(schema_definition: SchemaDefinition).void }
    # Initializes a new instance of the Builder class.
    #
    # @param schema_definition [SchemaDefinition] The schema definition.
    def initialize(schema_definition)
      @schema_definition = schema_definition
    end

    sig { returns(Hash) }
    # Retrieves the schema document.
    #
    # @return [Hash] The schema document.
    def schema
      @schema = schema_document
    end

    sig { returns(String) }
    # Returns the JSON representation of the schema document.
    #
    # @return [String] The JSON schema.
    def json_schema
      @json_schema ||= schema_document.to_json
    end

    sig { returns(Hash) }
    # Returns the schema document, building it if necessary.
    #
    # @return [Hash] The schema document.
    def schema_document
      @schema_document ||= build_schema
    end

    sig { returns(Hash) }
    # Builds the schema using the schema definition.
    #
    # Returns the built schema.
    def build_schema
      Builders::ObjectBuilder.new(@schema_definition).build
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
easy_talk-0.1.6 lib/easy_talk/builder.rb
easy_talk-0.1.5 lib/easy_talk/builder.rb
easy_talk-0.1.4 lib/easy_talk/builder.rb
easy_talk-0.1.3 lib/easy_talk/builder.rb
easy_talk-0.1.2 lib/easy_talk/builder.rb
easy_talk-0.1.1 lib/easy_talk/builder.rb
easy_talk-0.1.0 lib/easy_talk/builder.rb