Module: CurrentScope::ApplicationHelper
- Defined in:
- app/helpers/current_scope/application_helper.rb
Instance Method Summary collapse
-
#configured_subject_label(subject) ⇒ Object
The configured subject_label (Symbol or Proc) applied to a subject, or nil when unset or when it resolves to a blank value.
-
#current_scope_gid_label(gid) ⇒ Object
Best-effort label for a stored GID string (event actor/subject).
- #current_scope_holder_resource_label(scoped_assignment) ⇒ Object
-
#current_scope_holder_subject_label(assignment) ⇒ Object
Members-list labels that survive a stale/renamed polymorphic type — a removed subject or resource class must not 500 the page; fall back to "Type #id" the way the audit ledger does.
-
#current_scope_label(record) ⇒ Object
Best-effort human label for any host subject/resource.
-
#current_scope_subject_label(subject) ⇒ Object
Human label for a subject (user/account), honouring config.subject_label so a host on UUID keys can show email or a full name instead of an opaque id.
Instance Method Details
#configured_subject_label(subject) ⇒ Object
The configured subject_label (Symbol or Proc) applied to a subject, or nil when unset or when it resolves to a blank value.
40 41 42 43 44 45 46 47 |
# File 'app/helpers/current_scope/application_helper.rb', line 40 def configured_subject_label(subject) label = CurrentScope.config.subject_label if label.respond_to?(:call) label.call(subject).to_s.presence elsif label && subject.respond_to?(label) subject.public_send(label).to_s.presence end end |
#current_scope_gid_label(gid) ⇒ Object
Best-effort label for a stored GID string (event actor/subject). Falls back to the raw GID when the record is gone — the ledger outlives the identities it names.
67 68 69 70 |
# File 'app/helpers/current_scope/application_helper.rb', line 67 def current_scope_gid_label(gid) record = GlobalID::Locator.locate(gid) record ? current_scope_label(record) : gid end |
#current_scope_holder_resource_label(scoped_assignment) ⇒ Object
58 59 60 61 62 |
# File 'app/helpers/current_scope/application_helper.rb', line 58 def current_scope_holder_resource_label(scoped_assignment) current_scope_label(scoped_assignment.resource) rescue NameError, ActiveRecord::RecordNotFound "#{scoped_assignment.resource_type} ##{scoped_assignment.resource_id}" end |
#current_scope_holder_subject_label(assignment) ⇒ Object
Members-list labels that survive a stale/renamed polymorphic type — a removed subject or resource class must not 500 the page; fall back to "Type #id" the way the audit ledger does.
52 53 54 55 56 |
# File 'app/helpers/current_scope/application_helper.rb', line 52 def current_scope_holder_subject_label(assignment) current_scope_subject_label(assignment.subject) rescue NameError, ActiveRecord::RecordNotFound "#{assignment.subject_type} ##{assignment.subject_id}" end |
#current_scope_label(record) ⇒ Object
Best-effort human label for any host subject/resource. Prefers a record's own current_scope_label (the Scopeable mixin gives every pickable model one) so the label a model declares is the label shown everywhere — the picker, the chips, and the ledger (see Event.label_for) all agree.
7 8 9 10 11 12 13 |
# File 'app/helpers/current_scope/application_helper.rb', line 7 def current_scope_label(record) return "(none)" if record.nil? return record.current_scope_label if record.respond_to?(:current_scope_label) name = record.try(:name) || record.try(:email) || record.try(:title) name || "#{record.class.name} ##{record.id}" end |
#current_scope_subject_label(subject) ⇒ Object
Human label for a subject (user/account), honouring config.subject_label so a host on UUID keys can show email or a full name instead of an opaque id. Falls back to the best-effort current_scope_label.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/current_scope/application_helper.rb', line 18 def current_scope_subject_label(subject) return "(none)" if subject.nil? # A configured label that resolves to nil/blank (e.g. :email on a subject # with no email yet) must not render as an empty row — fall through to the # default human-identifier chain rather than showing "". configured = configured_subject_label(subject) return configured if configured # Default: a subject is a person, so prefer human identifiers over a # generic "Class #id" — including when the model includes Scopeable, whose # current_scope_label is id-based. Covers `email` and Rails 8 auth's # `email_address`. Config overrides this entirely. full_name = [ subject.try(:first_name), subject.try(:last_name) ].compact.join(" ").presence # .presence on each identifier: a stored empty/whitespace email ("") is # truthy in Ruby and would otherwise short-circuit to a blank label. subject.try(:email).presence || subject.try(:email_address).presence || subject.try(:name).presence || full_name || current_scope_label(subject) end |