Exception: Treaty::Exceptions::MethodName

Inherits:
Base
  • Object
show all
Defined in:
lib/treaty/exceptions/method_name.rb

Overview

Raised when an unknown method is called in the version DSL

Purpose

Prevents typos and invalid method calls in the treaty version definition DSL. Ensures only recognized DSL methods are used within version blocks.

Usage

Raised automatically by method_missing in VersionFactory:

version 1 do
  deprecated true                     # Valid
  summary "Version 1"                 # Valid

  invalid_method "foo"  # Raises Treaty::Exceptions::MethodName
end

Integration

Typically caught during development/testing rather than production:

rescue_from Treaty::Exceptions::MethodName, with: :render_dsl_error

def render_dsl_error(exception)
  render json: { error: exception.message }, status: :internal_server_error
end

Valid DSL Methods

Within a version block, these methods are valid:

  • deprecated(condition) - Mark version as deprecated
  • summary(text) - Add version description
  • request(&block) - Define request schema
  • response(status, &block) - Define response schema
  • delegate_to(executor, method) - Set executor

Prevention

Always refer to Treaty documentation for valid DSL methods. This exception helps catch typos early in development.