Class: Synthra::Behaviors::Deprecated

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/behaviors/deprecated.rb

Overview

Emits deprecation warnings during data generation

The Deprecated behavior is used to mark schemas as deprecated. When data is generated from a deprecated schema, a warning is logged/printed to alert developers.

Examples:

DSL usage

OldSchema:
  @deprecated "Use NewSchema instead"
  field: text

Programmatic check

behavior = Deprecated.new("Use NewSchema instead")
behavior.apply(result, context)  # Prints warning

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Synthra::Behaviors::Base

Instance Method Details

#apply(result, context = nil) ⇒ Object

Apply the deprecation warning

Emits a warning message about the deprecated schema. The warning is sent to Synthra.logger if available, otherwise to $stderr.

Parameters:

  • result (Object)

    the generated data (passed through unchanged)

  • context (Generator::Context, nil) (defaults to: nil)

    generation context

Returns:

  • (Object)

    the unchanged result



59
60
61
62
# File 'lib/synthra/behaviors/deprecated.rb', line 59

def apply(result, context = nil)
  emit_warning(context)
  result
end

#build_warning_message(schema_name) ⇒ String (private)

Build the warning message

Parameters:

  • schema_name (String)

    name of the deprecated schema

Returns:

  • (String)

    formatted warning message



91
92
93
94
95
# File 'lib/synthra/behaviors/deprecated.rb', line 91

def build_warning_message(schema_name)
  deprecation_note = value.is_a?(String) ? value : "This schema is deprecated"
  
  "DEPRECATED: Schema '#{schema_name}' - #{deprecation_note}"
end

#emit_warning(context) ⇒ void (private)

This method returns an undefined value.

Emit the deprecation warning

Parameters:



73
74
75
76
77
78
79
80
81
82
# File 'lib/synthra/behaviors/deprecated.rb', line 73

def emit_warning(context)
  schema_name = context&.instance_variable_get(:@schema_name) || "Unknown"
  message = build_warning_message(schema_name)

  if Synthra.configuration.logger
    Synthra.configuration.logger.warn(message)
  else
    warn "[Synthra] #{message}"
  end
end