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

Instance Method Details

#all_personasActiveRecord::Relation<Protege::Persona>

Fetch every Persona ordered by name for sidebar listing.

Returns:

  • (ActiveRecord::Relation<Protege::Persona>)

    personas ordered alphabetically



23
24
25
# File 'app/helpers/protege/personas_helper.rb', line 23

def all_personas
  Persona.order(:name)
end

#available_email_domainsActiveRecord::Relation<Protege::EmailDomain>

List active email domains for the persona form's domain selector.

Returns:



16
17
18
# File 'app/helpers/protege/personas_helper.rb', line 16

def available_email_domains
  EmailDomain.all
end

#available_persona_typesArray<Class>

List the loaded Persona subclasses for the new-persona type selector.

Returns:

  • (Array<Class>)

    the Persona descendant classes



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>"

Parameters:

Returns:

  • (String)

    the "name <Type>" label



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.

Parameters:

Returns:

  • (ActiveSupport::SafeBuffer)

    a green dot when active, red otherwise



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.

Parameters:

Returns:

  • (Array<Class>)

    the toggleable tool classes



72
73
74
75
76
# File 'app/helpers/protege/personas_helper.rb', line 72

def persona_tool_options(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.

Parameters:

  • persona (Protege::Persona)

    the persona whose reply (+message_resolvers+) chain to format

Returns:

  • (Hash{String => String})

    resolver-name => configuration summary



55
56
57
58
59
60
61
# File 'app/helpers/protege/personas_helper.rb', line 55

def resolver_pairs(persona)
  pairs = persona.message_resolvers.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