Class: Route
Constant Summary
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Instance Method Summary
collapse
split_query_to_search_terms
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Instance Method Details
#conflicting_redirects ⇒ Object
60
61
62
|
# File 'app/models/route.rb', line 60
def conflicting_redirects
RedirectRoute.matching_path_and_descendants(path)
end
|
#create_redirect(path) ⇒ Object
64
65
66
|
# File 'app/models/route.rb', line 64
def create_redirect(path)
RedirectRoute.create(source: source, path: path)
end
|
#delete_conflicting_redirects ⇒ Object
56
57
58
|
# File 'app/models/route.rb', line 56
def delete_conflicting_redirects
conflicting_redirects.delete_all
end
|
#rename_descendants ⇒ Object
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
54
|
# File 'app/models/route.rb', line 26
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
next if attributes.empty?
old_path = route.path
route.update_columns(attributes.merge(updated_at: Time.current))
route.create_redirect(old_path) if attributes[:path]
end
end
|