Class: JSONRPC::RoutesDsl Private
- Inherits:
-
Object
- Object
- JSONRPC::RoutesDsl
- Defined in:
- lib/jsonrpc/railtie/routes_dsl.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.
DSL context for defining JSON-RPC routes within a jsonrpc block
Instance Method Summary collapse
-
#batch(to:) ⇒ void
private
Define a route for handling JSON-RPC batch requests.
-
#initialize(mapper, path_prefix = '/') ⇒ RoutesDsl
constructor
private
Initialize a new routes DSL context.
-
#method(jsonrpc_method, to:) ⇒ void
private
Define a JSON-RPC method route.
-
#namespace(name) ⇒ void
private
Create a namespace for grouping related JSON-RPC methods.
Constructor Details
#initialize(mapper, path_prefix = '/') ⇒ RoutesDsl
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.
Initialize a new routes DSL context
52 53 54 55 56 |
# File 'lib/jsonrpc/railtie/routes_dsl.rb', line 52 def initialize(mapper, path_prefix = '/') @mapper = mapper @path_prefix = path_prefix @namespace_stack = [] end |
Instance Method Details
#batch(to:) ⇒ void
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.
This method returns an undefined value.
Define a route for handling JSON-RPC batch requests
91 92 93 94 95 96 97 98 |
# File 'lib/jsonrpc/railtie/routes_dsl.rb', line 91 def batch(to:) constraint = JSONRPC::BatchConstraint.new @mapper.post @path_prefix, { to: to, constraints: constraint } end |
#method(jsonrpc_method, to:) ⇒ void
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.
This method returns an undefined value.
Define a JSON-RPC method route
73 74 75 76 77 78 79 80 81 |
# File 'lib/jsonrpc/railtie/routes_dsl.rb', line 73 def method(jsonrpc_method, to:) full_method_name = build_full_method_name(jsonrpc_method) constraint = JSONRPC::MethodConstraint.new(full_method_name) @mapper.post @path_prefix, { to: to, constraints: constraint } end |
#namespace(name) ⇒ void
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.
This method returns an undefined value.
Create a namespace for grouping related JSON-RPC methods
Namespaces can be nested to create hierarchical method names. Each level of nesting adds a dot-separated prefix to the method names.
126 127 128 129 130 |
# File 'lib/jsonrpc/railtie/routes_dsl.rb', line 126 def namespace(name, &) @namespace_stack.push(name) instance_eval(&) @namespace_stack.pop end |