Module: Ruact::Server::ClassMethods
- Defined in:
- lib/ruact/server.rb
Overview
Story 9.3 — the JS-identifier rename escape hatch (AC4). Naming is derived from the route table by default (Ruact::ServerFunctions::RouteSource); when two routes collide in the merged JS namespace the codegen fails loudly at boot, and this macro is how a host breaks the tie (or simply prefers a different name):
class PostsController < ApplicationController
include Ruact::Server
ruact_function_name :publish_all, as: "publishEverything"
end
The override is keyed by ACTION name (string) and read by the codegen via #__ruact_function_name_overrides. The target identifier is validated at class-load time against the same JS-identifier shape + reserved-word rules the codegen enforces, so a bad override fails at boot, never at codegen.
Constant Summary collapse
- RUACT_VALID_JS_IDENTIFIER =
JS identifier shape — mirror of Ruact::ServerFunctions::Codegen::VALID_JS_IDENTIFIER (kept local so the concern does not depend on the codegen module).
/\A[A-Za-z_$][A-Za-z0-9_$]*\z/
Instance Method Summary collapse
-
#__ruact_function_name_overrides ⇒ Hash{String=>String}
The action-name → js-identifier override map for this controller, consulted by Ruact::ServerFunctions::RouteSource.
- #ruact_function_name(action, as:) ⇒ Object
Instance Method Details
#__ruact_function_name_overrides ⇒ Hash{String=>String}
The action-name → js-identifier override map for this controller, consulted by Ruact::ServerFunctions::RouteSource. Per-controller (not inherited) — overrides describe the host’s own actions.
173 174 175 |
# File 'lib/ruact/server.rb', line 173 def __ruact_function_name_overrides @__ruact_function_name_overrides ||= {} end |
#ruact_function_name(action, as:) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ruact/server.rb', line 150 def ruact_function_name(action, as:) js = as.to_s unless js.match?(RUACT_VALID_JS_IDENTIFIER) raise Ruact::ConfigurationError, "ruact_function_name :#{action}, as: #{as.inspect} — " \ "\"#{js}\" is not a valid JS identifier (must match #{RUACT_VALID_JS_IDENTIFIER.inspect})" end if Ruact::ServerFunctions::NameBridge::RESERVED_JS_IDENTIFIERS.include?(js) || Ruact::ServerFunctions::NameBridge::RESERVED_BY_RUACT.include?(js) raise Ruact::ConfigurationError, "ruact_function_name :#{action}, as: #{as.inspect} — " \ "\"#{js}\" is a reserved JS word or is already bound by the ruact runtime " \ "(`_makeRef` / `_makeServerFunction` / `revalidate`); pick another name" end __ruact_function_name_overrides[action.to_s] = js end |