From c4a2af54e7674c742feb23e8ed1c5acbc642bb82 Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Thu, 16 Nov 2023 13:58:39 +0300 Subject: [PATCH] Add documentation for AttributeSchemaGenerator class --- lib/schemable/attribute_schema_generator.rb | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/schemable/attribute_schema_generator.rb b/lib/schemable/attribute_schema_generator.rb index bcf5b08..33eca63 100644 --- a/lib/schemable/attribute_schema_generator.rb +++ b/lib/schemable/attribute_schema_generator.rb @@ -1,7 +1,16 @@ module Schemable + # The AttributeSchemaGenerator class is responsible for generating JSON schemas for model attributes. + # It includes methods for generating the overall schema and individual attribute schemas. + # + # @see Schemable class AttributeSchemaGenerator attr_reader :model_definition, :configuration, :model, :schema_modifier, :response + # Initializes a new AttributeSchemaGenerator instance. + # + # @param model_definition [ModelDefinition] The model definition to generate the schema for. + # @example + # generator = AttributeSchemaGenerator.new(model_definition) def initialize(model_definition) @model_definition = model_definition @model = model_definition.model @@ -10,7 +19,11 @@ module Schemable @response = nil end - # Generate the JSON schema for attributes + # Generates the JSON schema for the model attributes. + # + # @return [Hash] The generated schema. + # @example + # schema = generator.generate def generate schema = { type: :object, @@ -37,7 +50,12 @@ module Schemable schema end - # Generate the JSON schema for a specific attribute + # Generates the JSON schema for a specific attribute. + # + # @param attribute [Symbol, String] The attribute to generate the schema for. + # @return [Hash] The generated schema for the attribute. + # @example + # attribute_schema = generator.generate_attribute_schema(:attribute_name) def generate_attribute_schema(attribute) if @configuration.orm == :mongoid # Get the column hash for the attribute