Module: Glib::JsonUi::Name
- Defined in:
- lib/glib/json_ui/name.rb
Overview
Helpers for the namespaced names that appear in the generated JSON as
view, action and template values.
Names are always written in canonical form in this codebase (panels/form)
regardless of what Config.name_separator is set to:
- Producing: run the canonical literal through `Name.for` (or build it
from parts with `Name.join`) so it is emitted using the configured
separator.
- Consuming: compare with `Name.eq?` / `Name.start_with?`, which accept
either separator. Reads are deliberately separator-agnostic so tools
like the crawler work against any app, and against fixtures recorded
before the switch.
Class Method Summary collapse
-
.eq?(value, canonical) ⇒ Boolean
Either side may use either separator.
-
.for(canonical) ⇒ Object
'windows/reload' -> 'windows/reload' or 'windows_reload'.
-
.join(components) ⇒ Object
['windows', 'reload'] -> 'windows/reload' or 'windows_reload'.
-
.normalize(value) ⇒ Object
Rewrites a name coming from JSON into canonical (slash) form.
- .start_with?(value, *canonicals) ⇒ Boolean
Class Method Details
.eq?(value, canonical) ⇒ Boolean
Either side may use either separator.
40 41 42 |
# File 'lib/glib/json_ui/name.rb', line 40 def eq?(value, canonical) normalize(value) == normalize(canonical) end |
.for(canonical) ⇒ Object
'windows/reload' -> 'windows/reload' or 'windows_reload'
19 20 21 22 23 |
# File 'lib/glib/json_ui/name.rb', line 19 def for(canonical) return canonical unless canonical.is_a?(String) canonical.tr('/', Config.name_separator) end |
.join(components) ⇒ Object
['windows', 'reload'] -> 'windows/reload' or 'windows_reload'
26 27 28 |
# File 'lib/glib/json_ui/name.rb', line 26 def join(components) components.join(Config.name_separator) end |
.normalize(value) ⇒ Object
Rewrites a name coming from JSON into canonical (slash) form. Only the
first separator is rewritten: the second part may itself be camelCase
but never contains a separator (e.g. storageItems_set).
33 34 35 36 37 |
# File 'lib/glib/json_ui/name.rb', line 33 def normalize(value) return value unless value.is_a?(String) value.sub('_', '/') end |
.start_with?(value, *canonicals) ⇒ Boolean
44 45 46 47 48 49 |
# File 'lib/glib/json_ui/name.rb', line 44 def start_with?(value, *canonicals) normalized = normalize(value) return false unless normalized.is_a?(String) canonicals.any? { |canonical| normalized.start_with?(normalize(canonical)) } end |