Class: Route
Constant Summary
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_WORD
Instance Method Summary
collapse
at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order
Instance Method Details
#conflicting_redirects ⇒ Object
59
60
61
|
# File 'app/models/route.rb', line 59
def conflicting_redirects
RedirectRoute.matching_path_and_descendants(path)
end
|
#create_redirect(path) ⇒ Object
63
64
65
|
# File 'app/models/route.rb', line 63
def create_redirect(path)
RedirectRoute.create(source: source, path: path)
end
|
#delete_conflicting_redirects ⇒ Object
55
56
57
|
# File 'app/models/route.rb', line 55
def delete_conflicting_redirects
conflicting_redirects.delete_all
end
|
#rename_descendants ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/models/route.rb', line 25
def rename_descendants
return unless saved_change_to_path? || saved_change_to_name?
descendant_routes = self.class.inside_path(path_before_last_save)
descendant_routes.each do |route|
attributes = {}
if saved_change_to_path? && route.path.present?
attributes[:path] = route.path.sub(path_before_last_save, path)
end
if saved_change_to_name? && name_before_last_save.present? && route.name.present?
attributes[:name] = route.name.sub(name_before_last_save, name)
end
if attributes.present?
old_path = route.path
route.update_columns(attributes.merge(updated_at: Time.current))
route.create_redirect(old_path) if attributes[:path]
end
end
end
|