Class: Banzai::Filter::References::DesignReferenceFilter

Inherits:
AbstractReferenceFilter show all
Defined in:
lib/banzai/filter/references/design_reference_filter.rb

Defined Under Namespace

Classes: Identifier

Constant Summary

Constants inherited from AbstractReferenceFilter

AbstractReferenceFilter::REFERENCE_PLACEHOLDER, AbstractReferenceFilter::REFERENCE_PLACEHOLDER_PATTERN

Instance Method Summary collapse

Methods inherited from AbstractReferenceFilter

#call, #find_object_cached, #find_object_from_link, #find_object_from_link_cached, #from_ref_cached, #identifier, #initialize, #object_link_filter, #object_link_text, #object_link_text_extras, #object_link_title, #parent, #parent_type, #references_in, #symbol_from_match, #url_for_object_cached, #wrap_link

Methods included from CrossProjectReference

#parent_from_ref

Methods inherited from ReferenceFilter

call, #call, #call_and_update_nodes, #each_node, #group, #initialize, #nodes, #object_class, #project, #references_in, #requires_unescaping?

Methods included from OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

This class inherits a constructor from Banzai::Filter::References::AbstractReferenceFilter

Instance Method Details

#data_attributes_for(_text, _project, design, **_kwargs) ⇒ Object


67
68
69
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 67

def data_attributes_for(_text, _project, design, **_kwargs)
  super.merge(issue: design.issue_id)
end

#find_object(project, identifier) ⇒ Object


38
39
40
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 38

def find_object(project, identifier)
  reference_cache.records_per_parent[project][identifier]
end

#object_symObject


71
72
73
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 71

def object_sym
  :design
end

#parent_records(project, identifiers) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 42

def parent_records(project, identifiers)
  return [] unless project.design_management_enabled?

  iids        = identifiers.map(&:issue_iid).to_set
  issues      = project.issues.where(iid: iids)
  id_for_iid  = issues.index_by(&:iid).transform_values(&:id)
  issue_by_id = issues.index_by(&:id)

  designs(identifiers, id_for_iid).each do |d|
    issue = issue_by_id[d.issue_id]
    # optimisation: assign values we have already fetched
    d.project = project
    d.issue = issue
  end
end

#parse_symbol(raw, match_data) ⇒ Object


75
76
77
78
79
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 75

def parse_symbol(raw, match_data)
  filename = match_data[:url_filename]
  iid = match_data[:issue].to_i
  Identifier.new(filename: CGI.unescape(filename), issue_iid: iid)
end

#record_identifier(design) ⇒ Object


81
82
83
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 81

def record_identifier(design)
  Identifier.new(filename: design.filename, issue_iid: design.issue.iid)
end

#relation_for_paths(paths) ⇒ Object


58
59
60
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 58

def relation_for_paths(paths)
  super.includes(:route, :namespace, :group)
end

#url_for_object(design, project) ⇒ Object


62
63
64
65
# File 'lib/banzai/filter/references/design_reference_filter.rb', line 62

def url_for_object(design, project)
  path_options = { vueroute: design.filename }
  Gitlab::Routing.url_helpers.designs_project_issue_path(project, design.issue, path_options)
end