Module: LcpRuby::Menu
- Defined in:
- lib/lcp_ruby/menu.rb
Overview
Small process-local helpers used by the shipped menu renderers.
- Lives outside Metadata
-
because the renderers do runtime work
(logging, fallback derivations) that isn’t metadata.
Class Method Summary collapse
-
.reset_warning_state! ⇒ Object
Test hook to reset the latch between examples.
-
.warn_user_menu_no_name(_user) ⇒ Object
Logs a one-shot warning when the configured user model responds to neither ‘:name` nor `:email`.
Class Method Details
.reset_warning_state! ⇒ Object
Test hook to reset the latch between examples.
41 42 43 |
# File 'lib/lcp_ruby/menu.rb', line 41 def reset_warning_state! @warn_no_name_mutex.synchronize { @warned_no_name = nil } end |
.warn_user_menu_no_name(_user) ⇒ Object
Logs a one-shot warning when the configured user model responds to neither ‘:name` nor `:email`. The shipped `lcp_ruby/user_menu` renderer falls back to “User <id>” in that case; this warning helps configurators discover the missing method (typically: forgot to add `name:` to the user model, or replace the renderer with a host-side variant).
Suppressed in ‘Rails.env.test?` so the test suite doesn’t spam stderr when fixtures use a bare user object. The mutex makes the latch genuinely thread-safe — Puma running multiple threads on a single process won’t double-log.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lcp_ruby/menu.rb', line 20 def (_user) return if defined?(Rails) && Rails.respond_to?(:env) && Rails.env.test? should_log = false @warn_no_name_mutex.synchronize do unless @warned_no_name @warned_no_name = true should_log = true end end return unless should_log return unless defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger Rails.logger.warn( "[LcpRuby::Menu] current_user responds to neither :name nor :email; " \ "falling back to \"User <id>\". Implement #name or #email or replace " \ "the renderer via `render: my_app/user_menu`." ) end |