Module: Referable

Extended by:
ActiveSupport::Concern
Included in:
AlertManagement::Alert, Commit, CommitRange, DesignManagement::Design, ExternalIssue, HasRepository, Issue, Label, MergeRequest, Namespace, Operations::FeatureFlag, Timebox, User
Defined in:
app/models/concerns/referable.rb

Overview

Referable concern

Contains functionality related to making a model referable in Markdown, such as “#1”, “!2”, “~3”, etc.

Instance Method Summary collapse

Instance Method Details

#referable_inspectObject



43
44
45
46
47
48
49
# File 'app/models/concerns/referable.rb', line 43

def referable_inspect
  if respond_to?(:id)
    "#<#{self.class.name} id:#{id} #{to_reference(full: true)}>"
  else
    "#<#{self.class.name} #{to_reference(full: true)}>"
  end
end


34
35
36
# File 'app/models/concerns/referable.rb', line 34

def reference_link_text(from = nil)
  to_reference(from)
end

#to_reference(_from = nil, full:) ⇒ Object

Returns the String necessary to reference this object in Markdown

from - Referring parent object

This should be overridden by the including class.

Examples:

Issue.first.to_reference               # => "#1"
Issue.last.to_reference(other_project) # => "cross-project#1"

Returns a String



22
23
24
# File 'app/models/concerns/referable.rb', line 22

def to_reference(_from = nil, full:)
  ''
end

#to_reference_base(from = nil, full:, absolute_path: false) ⇒ Object

If this referable object can serve as the base for the reference of child objects (e.g. projects are the base of issues), but it is formatted differently, then you may wish to override this method.



30
31
32
# File 'app/models/concerns/referable.rb', line 30

def to_reference_base(from = nil, full:, absolute_path: false)
  to_reference(from, full: full)
end