Class: JSONRPC::BatchConstraint Private

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonrpc/railtie/batch_constraint.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This constraint allows Rails routes to be matched based on JSON-RPC batch requests, enabling batch-specific routing to dedicated controllers.

Examples:

Using in Rails routes

post '/', to: 'jsonrpc#handle_batch', constraints: JSONRPC::BatchConstraint.new

Instance Method Summary collapse

Instance Method Details

#matches?(request) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the request is a JSON-RPC batch request

Parameters:

  • request (ActionDispatch::Request)

    The Rails request object

Returns:

  • (Boolean)

    true if the request is a batch request, false otherwise



18
19
20
21
22
23
# File 'lib/jsonrpc/railtie/batch_constraint.rb', line 18

def matches?(request)
  jsonrpc_batch = request.env['jsonrpc.batch']

  # Return true if we have a batch request in the environment
  !jsonrpc_batch.nil?
end