Module: Protege::PersonasHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/protege/personas_helper.rb
Overview
View helpers for persona pages — selectors, labels, status, and resolver display.
Instance Method Summary collapse
-
#all_personas ⇒ ActiveRecord::Relation<Protege::Persona>
Fetch every
Personaordered by name for sidebar listing. -
#available_email_domains ⇒ ActiveRecord::Relation<Protege::EmailDomain>
List active email domains for the persona form's domain selector.
-
#available_persona_types ⇒ Array<Class>
List the loaded
Personasubclasses for the new-persona type selector. -
#persona_label(persona) ⇒ String
Format a persona's name together with its type for display.
-
#persona_status(persona) ⇒ ActiveSupport::SafeBuffer
Render a status dot reflecting whether a persona is available.
-
#persona_tool_options(persona) ⇒ Array<Class>
The tool classes a persona's operator may toggle — the checkbox universe on the persona form.
-
#resolver_pairs(persona) ⇒ Hash{String => String}
Format a persona's resolver chain as a hash suitable for
info_card(rendered full-width, since the resolver class names are long).
Instance Method Details
#all_personas ⇒ ActiveRecord::Relation<Protege::Persona>
Fetch every Persona ordered by name for sidebar listing.
23 24 25 |
# File 'app/helpers/protege/personas_helper.rb', line 23 def all_personas Persona.order(:name) end |
#available_email_domains ⇒ ActiveRecord::Relation<Protege::EmailDomain>
List active email domains for the persona form's domain selector.
16 17 18 |
# File 'app/helpers/protege/personas_helper.rb', line 16 def available_email_domains EmailDomain.all end |
#available_persona_types ⇒ Array<Class>
List the loaded Persona subclasses for the new-persona type selector.
9 10 11 |
# File 'app/helpers/protege/personas_helper.rb', line 9 def available_persona_types Persona.descendants end |
#persona_label(persona) ⇒ String
Format a persona's name together with its type for display.
persona_label(persona) # => "Bob <Agent>"
33 34 35 |
# File 'app/helpers/protege/personas_helper.rb', line 33 def persona_label(persona) "#{persona.name} <#{persona.class.display_name}>" end |
#persona_status(persona) ⇒ ActiveSupport::SafeBuffer
Render a status dot reflecting whether a persona is available.
41 42 43 44 45 46 47 |
# File 'app/helpers/protege/personas_helper.rb', line 41 def persona_status(persona) if persona.active? status_dot('Available', :green) else status_dot('Unavailable', :red) end end |
#persona_tool_options(persona) ⇒ Array<Class>
The tool classes a persona's operator may toggle — the checkbox universe on the persona form.
This is the persona's grant (its code-declared ceiling), or every registered tool when no grant was declared. It is deliberately the grant rather than the effective set: the operator toggles within what the code allows, so a tool disabled in the DB still appears (unchecked) and can be switched back on, while a tool outside the grant is never offered.
72 73 74 75 76 |
# File 'app/helpers/protege/personas_helper.rb', line 72 def (persona) grant = persona.class.tool_grant grant ? ToolMixin.registered.select { grant.include?(_1.id) } : ToolMixin.registered end |
#resolver_pairs(persona) ⇒ Hash{String => String}
Format a persona's resolver chain as a hash suitable for info_card (rendered full-width, since
the resolver class names are long). Each entry maps the resolver's short class name to a summary
of its positional args, keyword args, and whether it was given a block.
55 56 57 58 59 60 61 |
# File 'app/helpers/protege/personas_helper.rb', line 55 def resolver_pairs(persona) pairs = persona..entries.each_with_object({}) do |(klass, args, kwargs, block), accumulator| accumulator[klass.name.demodulize] = resolver_config(args, kwargs, block) end pairs.any? ? pairs : { 'Resolvers' => 'None configured' } end |