Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fixes Performance/DeleteSuffix offenses

Klaus Zandersbf1293a36167
diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rb
index 4690537584b..67dd50a6ab5 100644
--- a/app/contracts/base_contract.rb
+++ b/app/contracts/base_contract.rb
@@ -101,7 +101,7 @@ class BaseContract < Disposable::Twin
private
def add_writable(attribute, writable)
- attribute_name = attribute.to_s.gsub /_id\z/, ''
+ attribute_name = attribute.to_s.delete_suffix('_id')
unless writable == false
writable_attributes << attribute_name
@@ -244,7 +244,7 @@ class BaseContract < Disposable::Twin
attribute_permissions = collect_ancestor_attributes(:attribute_permissions)
attributes.reject do |attribute|
- canonical_attribute = attribute.gsub(/_id\z/, '')
+ canonical_attribute = attribute.delete_suffix('_id')
permissions = attribute_permissions[canonical_attribute] ||
attribute_permissions["#{canonical_attribute}_id"] ||
diff --git a/lib/open_project/patches/active_record_i18n.rb b/lib/open_project/patches/active_record_i18n.rb
index 9a8eb2f49e0..486a6ecf2fd 100644
--- a/lib/open_project/patches/active_record_i18n.rb
+++ b/lib/open_project/patches/active_record_i18n.rb
@@ -31,7 +31,7 @@ module ActiveRecord
include Redmine::I18n
def self.human_attribute_name(attr, options = {})
- attr = attr.to_s.gsub(/_id\z/, '')
+ attr = attr.to_s.delete_suffix('_id')
super
end
end