Project

General

Profile

Patch #40008 » delete-prefix-suffix-v2.patch

Go MAEDA, 2024-01-06 07:03

View differences:

app/controllers/repositories_controller.rb
230 230
  # Adds a related issue to a changeset
231 231
  # POST /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues
232 232
  def add_related_issue
233
    issue_id = params[:issue_id].to_s.sub(/^#/, '')
233
    issue_id = params[:issue_id].to_s.delete_prefix('#')
234 234
    @issue = @changeset.find_referenced_issue_by_id(issue_id)
235 235
    if @issue && (!@issue.visible? || @changeset.issues.include?(@issue))
236 236
      @issue = nil
app/controllers/settings_controller.rb
53 53
    @deliveries = ActionMailer::Base.perform_deliveries
54 54

  
55 55
    @guessed_host_and_path = request.host_with_port.dup
56
    @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
56
    @guessed_host_and_path << ("/#{Redmine::Utils.relative_url_root.delete_prefix('/')}") unless Redmine::Utils.relative_url_root.blank?
57 57

  
58 58
    @commit_update_keywords = Setting.commit_update_keywords.dup
59 59
    @commit_update_keywords = [{}] unless @commit_update_keywords.is_a?(Array) && @commit_update_keywords.any?
app/controllers/workflows_controller.rb
58 58

  
59 59
  def permissions
60 60
    if @roles && @trackers
61
      @fields = (Tracker::CORE_FIELDS_ALL - @trackers.map(&:disabled_core_fields).reduce(:&)).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
61
      @fields = (Tracker::CORE_FIELDS_ALL - @trackers.map(&:disabled_core_fields).reduce(:&)).map do |field|
62
        [field, l("field_#{field.delete_suffix('_id')}")]
63
      end
62 64
      @custom_fields = @trackers.map(&:custom_fields).flatten.uniq.sort
63 65
      @permissions = WorkflowPermission.rules_by_status_id(@trackers, @roles)
64 66
      @statuses.each {|status| @permissions[status.id] ||= {}}
app/helpers/issues_helper.rb
528 528

  
529 529
    case detail.property
530 530
    when 'attr'
531
      field = detail.prop_key.to_s.gsub(/\_id$/, "")
532
      label = l(("field_" + field).to_sym)
531
      field = detail.prop_key.to_s.delete_suffix('_id')
532
      label = l(("field_#{field}").to_sym)
533 533
      case detail.prop_key
534 534
      when 'due_date', 'start_date'
535 535
        value = format_date(detail.value.to_date) if detail.value
app/models/issue_query.rb
328 328
                        :sortable => "#{Issue.table_name}.is_private", :groupable => true)
329 329
    end
330 330

  
331
    disabled_fields = Tracker.disabled_core_fields(trackers).map {|field| field.sub(/_id$/, '')}
331
    disabled_fields = Tracker.disabled_core_fields(trackers).map {|field| field.delete_suffix('_id')}
332 332
    disabled_fields << "total_estimated_hours" if disabled_fields.include?("estimated_hours")
333 333
    @available_columns.reject! do |column|
334 334
      disabled_fields.include?(column.name.to_s)
......
479 479
  def sql_for_notes_field(field, operator, value)
480 480
    subquery = "SELECT 1 FROM #{Journal.table_name}" +
481 481
      " WHERE #{Journal.table_name}.journalized_type='Issue' AND #{Journal.table_name}.journalized_id=#{Issue.table_name}.id" +
482
      " AND (#{sql_for_field field, operator.sub(/^!/, ''), value, Journal.table_name, 'notes'})" +
482
      " AND (#{sql_for_field field, operator.delete_prefix('!'), value, Journal.table_name, 'notes'})" +
483 483
      " AND (#{Journal.visible_notes_condition(User.current, :skip_pre_condition => true)})"
484 484
    "#{/^!/.match?(operator) ? "NOT EXISTS" : "EXISTS"} (#{subquery})"
485 485
  end
app/models/query.rb
211 211
  def initialize(field, options)
212 212
    @field = field.to_s
213 213
    @options = options
214
    @options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
214
    @options[:name] ||= l(options[:label] || "field_#{field}".delete_suffix('_id'))
215 215
    # Consider filters with a Proc for values as remote by default
216 216
    @remote = options.key?(:remote) ? options[:remote] : options[:values].is_a?(Proc)
217 217
  end
app/views/trackers/_form.html.erb
17 17
  <% Tracker::CORE_FIELDS.each do |field| %>
18 18
  <label class="block">
19 19
    <%= check_box_tag 'tracker[core_fields][]', field, @tracker.core_fields.include?(field), :id => nil %>
20
    <%= l("field_#{field}".sub(/_id$/, '')) %>
20
    <%= l("field_#{field}".delete_suffix('_id')) %>
21 21
  </label>
22 22
  <% end %>
23 23
</p>
app/views/trackers/fields.html.erb
26 26
      </tr>
27 27
      <% Tracker::CORE_FIELDS.each do |field| %>
28 28
      <tr>
29
        <% field_name = l("field_#{field}".sub(/_id$/, '')) %>
29
        <% field_name = l("field_#{field}".delete_suffix('_id')) %>
30 30
        <td class="name">
31 31
          <%= link_to_function('', "toggleCheckboxesBySelector('input.core-field-#{field}')",
32 32
                               :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}",
config/initializers/10-patches.rb
4 4
  class Base
5 5
    # Translate attribute names for validation errors display
6 6
    def self.human_attribute_name(attr, options = {})
7
      prepared_attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '')
7
      prepared_attr = attr.to_s.delete_suffix('_id').sub(/^.+\./, '')
8 8
      class_prefix = name.underscore.tr('/', '_')
9 9

  
10 10
      redmine_default = [
lib/redmine/diff_table.rb
91 91
      if both_git_diff
92 92
        if file_name && arg == "/dev/null"
93 93
          # keep the original file name
94
          @file_name = file_name.sub(%r{^a/}, '')
94
          @file_name = file_name.delete_prefix('a/')
95 95
        else
96 96
          # remove leading a/
97
          @previous_file_name = file_name.sub(%r{^a/}, '') unless file_name == "/dev/null"
97
          @previous_file_name = file_name.delete_prefix('a/') unless file_name == "/dev/null"
98 98
          # remove leading b/
99
          @file_name = arg.sub(%r{^b/}, '')
99
          @file_name = arg.delete_prefix('b/')
100 100

  
101 101
          @previous_file_name = nil if @previous_file_name == @file_name
102 102
        end
lib/redmine/my_page.rb
81 81
        Dir.glob(
82 82
          "#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}"
83 83
        ).inject({}) do |h, file|
84
          name = File.basename(file).split('.').first.gsub(/^_/, '')
84
          name = File.basename(file).split('.').first.delete_prefix('_')
85 85
          h[name] = {:label => name.to_sym, :partial => "my/blocks/#{name}"}
86 86
          h
87 87
        end
lib/redmine/themes.rb
110 110

  
111 111
      def assets(dir, ext=nil)
112 112
        if ext
113
          Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).gsub(/\.#{ext}$/, '')}
113
          Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).delete_suffix(".#{ext}")}
114 114
        else
115 115
          Dir.glob("#{path}/#{dir}/*").collect {|f| File.basename(f)}
116 116
        end
test/coverage/html_formatter.rb
51 51
      end
52 52

  
53 53
      def shortened_filename(source_file)
54
        source_file.filename.gsub(SimpleCov.root, '.').gsub(/^\.\//, '')
54
        source_file.filename.gsub(SimpleCov.root, '.').delete_prefix('./')
55 55
      end
56 56

  
57 57
      def link_to_source_file(source_file)
test/functional/custom_fields_controller_test.rb
596 596
  def custom_field_classes
597 597
    files =
598 598
      Dir.glob(File.join(Rails.root, 'app/models/*_custom_field.rb')).
599
        map {|f| File.basename(f).sub(/\.rb$/, '')}
599
        map {|f| File.basename(f).delete_suffix('.rb')}
600 600
    classes = files.map {|x| x.classify.constantize}
601 601
    assert classes.size > 0
602 602
    classes
(2-2/2)