• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.0
/app/lib/diff_tools.rb
1
# frozen_string_literal: true
2

3
require "diff/lcs"
1✔
4

5
module DiffTools
1✔
6
  class SimpleDiff
1✔
7
    def initialize(old_value, new_value)
1✔
8
      # /\b/ matches word boundaries.
9
      # It is a zero-length match before and after each word,
10
      # and it preserves the whitespace between words.
11
      #
12
      # "cat dog".split /\b/ == ["cat", " ", "dog"]
13
      old_value = old_value.to_s.split(/\b/)
×
14
      new_value = new_value.to_s.split(/\b/)
×
15
      @changes = ::Diff::LCS.sdiff(old_value, new_value).chunk(&:action).map do |action, changes|
×
16
        {
17
          action:,
×
18
          old: changes.map(&:old_element).join,
19
          new: changes.map(&:new_element).join
20
        }
21
      end
22
    end
23

24
    def to_html
1✔
25
      @changes.map do |chunk|
×
26
        old_html = DiffTools.value_to_html(chunk[:old])
×
27
        new_html = DiffTools.value_to_html(chunk[:new])
×
28
        if chunk[:action] == "="
×
29
          new_html
×
30
        else
31
          (old_html.empty? ? "" : "<del>#{old_html}</del>") + \
×
32
            (new_html.empty? ? "" : "<ins>#{new_html}</ins>")
×
33
        end
34
      end.join
35
    end
36
  end
37

38
  def self.value_to_html(value)
1✔
39
    too_many_words_re = /
×
40
      ((?:\S+\s+){3}) # group 1: Three words, including trailing space
41
      (.+)            # group 2: Drop this
42
      ((?:\s+\S+){3}) # group 3: Three words, including leading space
43
    /x
44
    ellipsis = value.gsub(too_many_words_re, '\1...\3')
×
45
    CGI.escapeHTML(ellipsis)
×
46
  end
47
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc