Module: EasyTalk::Model::ClassMethods

Includes:
SchemaBase::ClassMethods
Defined in:
lib/easy_talk/model.rb

Overview

Module containing class-level methods for defining and accessing the schema of a model.

Instance Method Summary collapse

Instance Method Details

#additional_properties_allowed?Boolean Originally defined in module SchemaBase::ClassMethods

Returns:

  • (Boolean)

#define_schema(options = {}) { ... } ⇒ Object

Define the schema for the model using the provided block.

Examples:

Disable validations for a model

define_schema(validations: false) do
  property :name, String
end

Use a custom adapter

define_schema(validations: MyCustomAdapter) do
  property :name, String
end

Parameters:

  • options (Hash) (defaults to: {})

    Options for schema definition

Options Hash (options):

  • :validations (Boolean, Symbol, Class)

    Controls validation behavior:

    • true: Enable validations using the configured adapter (default behavior)
    • false: Disable validations for this model
    • :none: Use the NoneAdapter (no validations)
    • :active_model: Use the ActiveModelAdapter
    • CustomAdapter: Use a custom adapter class

Yields:

  • The block to define the schema.

Raises:

  • (ArgumentError)

    If the class does not have a name.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/easy_talk/model.rb', line 102

def define_schema(options = {}, &)
  super(&)

  # Store validation options for this model
  @validation_options = normalize_validation_options(options)

  # Initialize mutex eagerly for thread-safe schema-level validation application
  @schema_level_validation_lock = Mutex.new

  # Apply validations using the adapter system
  apply_schema_validations

  @schema_definition
end

#json_schemaHash Originally defined in module SchemaMethods

Returns the JSON schema for the model. This is the final output that includes the $schema keyword if configured.

Returns:

  • (Hash)

    The JSON schema for the model.

#propertiesObject Originally defined in module SchemaBase::ClassMethods

#ref_templateString Originally defined in module SchemaMethods

Returns the reference template for the model. When prefer_external_refs is enabled and the model has a schema ID, returns the external $id URI. Otherwise, returns the local $defs reference.

Returns:

  • (String)

    The reference template for the model.

#schemaObject Originally defined in module SchemaBase::ClassMethods

#schema_definitionObject Originally defined in module SchemaBase::ClassMethods