invoca-utils 0.6.1 → 0.7.0.colin.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.tool-versions +1 -1
- data/CHANGELOG.md +5 -7
- data/Gemfile.lock +1 -2
- data/invoca-utils.gemspec +0 -1
- data/lib/invoca/utils/diff.rb +0 -4
- data/lib/invoca/utils/version.rb +1 -1
- data/lib/invoca/utils.rb +0 -6
- data/spec/unit/diff_spec.rb +102 -0
- data/spec/unit/utils_spec.rb +5 -47
- metadata +5 -22
- data/spec/helpers/constant_overrides.rb +0 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 97f9b98c54883da05a6cb68be4bfebd61b858d5f5da7f8374bec356ae38a23b3
|
|
4
|
+
data.tar.gz: a84b9901a7fe50a44036b5f4f4b24367f0530e632e580b91fc6ff0ecec93d3ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b69462e99f162f2e22ea4444754ca04e8f42a34ac98aa60ba888d1bd4f6feec83b263ea6f2a0ffbd21f6384446625cf891aebcf191de32a9f34d556af9cd99d9
|
|
7
|
+
data.tar.gz: f6b637a19e6e0fa9ec3bd4ab20950d356a76e4cbae4d4251c2831d18fe718bd06c20e20fcbe7cc96fb6396b21d7ad7c3d21860f8fe42ae38887c45614c1d0c26
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.3.8
|
data/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.3.8
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
|
4
4
|
|
|
5
5
|
**Note:** This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.7.0] - UNRELEASED
|
|
8
|
+
### Removed
|
|
9
|
+
- Global `Diff` and `Diffable` constants; use `Invoca::Utils::Diff` and `Invoca::Utils::Diffable` instead
|
|
10
|
+
- Runtime dependency on `diff-lcs`; callers needing `Diff::LCS` should depend on and require `diff-lcs` directly
|
|
11
|
+
|
|
7
12
|
## [0.6.1] - 2025-03-27
|
|
8
13
|
### Fixed
|
|
9
14
|
- Fixed a global namespace collision with diff-lcs over the `Diff` constant
|
|
@@ -49,10 +54,3 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
|
49
54
|
### Added
|
|
50
55
|
- Enumerable::build_hash method ported from HoboSupport
|
|
51
56
|
- Enumerable::* operator ported from HoboSupport
|
|
52
|
-
|
|
53
|
-
[0.5.1]: https://github.com/Invoca/invoca-utils/compare/v0.5.0...v0.5.1
|
|
54
|
-
[0.5.0]: https://github.com/Invoca/invoca-utils/compare/v0.4.1...v0.5.0
|
|
55
|
-
[0.4.1]: https://github.com/Invoca/invoca-utils/compare/v0.4.0...v0.4.1
|
|
56
|
-
[0.4.0]: https://github.com/Invoca/invoca-utils/compare/v0.3.0...v0.4.0
|
|
57
|
-
[0.3.0]: https://github.com/Invoca/invoca-utils/compare/v0.2.0...v0.3.0
|
|
58
|
-
[0.2.0]: https://github.com/Invoca/invoca-utils/compare/v0.1.1...v0.2.0
|
data/Gemfile.lock
CHANGED
data/invoca-utils.gemspec
CHANGED
data/lib/invoca/utils/diff.rb
CHANGED
data/lib/invoca/utils/version.rb
CHANGED
data/lib/invoca/utils.rb
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Invoca::Utils::Diff do
|
|
6
|
+
describe ".compare" do
|
|
7
|
+
it "does nothing when identical" do
|
|
8
|
+
expect(described_class.compare(['a', 'b'], ['a', 'b'])).to eq('')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "detects additions" do
|
|
12
|
+
expect(described_class.compare(['a', 'c'], ['a', 'b', 'c'])).to eq(
|
|
13
|
+
" a\n+ b\n c\n"
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "detects additions at the front" do
|
|
18
|
+
expect(described_class.compare(['b', 'c'], ['a', 'b', 'c'])).to eq(
|
|
19
|
+
"+ a\n b\n c\n"
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "detects additions at the end" do
|
|
24
|
+
expect(described_class.compare(['a', 'b'], ['a', 'b', 'c'])).to eq(
|
|
25
|
+
" a\n b\n+ c\n"
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "detects deletions" do
|
|
30
|
+
expect(described_class.compare(['a', 'b', 'c'], ['a', 'c'])).to eq(
|
|
31
|
+
" a\n- b\n c\n"
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "detects deletions at the front" do
|
|
36
|
+
expect(described_class.compare(['a', 'b', 'c'], ['b', 'c'])).to eq(
|
|
37
|
+
"- a\n b\n c\n"
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "detects deletions at the end" do
|
|
42
|
+
expect(described_class.compare(['a', 'b', 'c'], ['a', 'b'])).to eq(
|
|
43
|
+
" a\n b\n- c\n"
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "detects changes" do
|
|
48
|
+
expect(described_class.compare(['a', 'b1', 'c'], ['a', 'b2', 'c'])).to eq(
|
|
49
|
+
" a\n- b1\n+ b2\n c\n"
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "detects changes at the front" do
|
|
54
|
+
expect(described_class.compare(['a1', 'b', 'c'], ['a2', 'b', 'c'])).to eq(
|
|
55
|
+
"- a1\n+ a2\n b\n c\n"
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "detects changes at the end" do
|
|
60
|
+
expect(described_class.compare(['a', 'b', 'c1'], ['a', 'b', 'c2'])).to eq(
|
|
61
|
+
" a\n b\n- c1\n+ c2\n"
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "detects multi-line changes" do
|
|
66
|
+
expect(described_class.compare(['a', 'b1', 'b2', 'd'], ['a', 'c', 'd'])).to eq(
|
|
67
|
+
" a\n- b1\n- b2\n+ c\n d\n"
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "detects multi-line changes at the front" do
|
|
72
|
+
expect(described_class.compare(['a1', 'b1', 'd'], ['a2', 'b2', 'b3', 'd'])).to eq(
|
|
73
|
+
"- a1\n- b1\n+ a2\n+ b2\n+ b3\n d\n"
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "detects multi-line changes at the end" do
|
|
78
|
+
expect(described_class.compare(['a', 'b', 'd1'], ['a', 'b', 'd2', 'd3'])).to eq(
|
|
79
|
+
" a\n b\n- d1\n+ d2\n+ d3\n"
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "uses inspect on complex data types and includes nested diff" do
|
|
84
|
+
expect(described_class.compare(['a', 'b', [1, 2]], ['a', 'b', [1, 2, 3], 'c'])).to eq(
|
|
85
|
+
" a\n b\n- [1, 2]\nNested array diff:\n 1\n 2\n+ 3\n\n+ [1, 2, 3]\n+ c\n"
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "includes nested diff on array of hashes" do
|
|
90
|
+
output = described_class.compare(
|
|
91
|
+
['a', 'b', { a: 1, b: 2 }],
|
|
92
|
+
['a', 'b', { a: 1, b: 5, c: 3 }]
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
expect(output).to match(/\- \{.*\}/)
|
|
96
|
+
expect(output).to include("Nested hash diff:")
|
|
97
|
+
expect(output).to include("[:b] expected 2, was 5")
|
|
98
|
+
expect(output).to include("[:c] not expected, was 3")
|
|
99
|
+
expect(output).to match(/\+ \{.*\}/)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
data/spec/unit/utils_spec.rb
CHANGED
|
@@ -1,55 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative '../spec_helper'
|
|
4
|
-
require_relative '../helpers/constant_overrides'
|
|
5
4
|
|
|
6
5
|
describe Invoca::Utils do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
setup_constant_overrides
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
after do
|
|
15
|
-
cleanup_constant_overrides
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "define Diff as Invoca::Utils::Diff" do
|
|
19
|
-
expect(Invoca::Utils::Diff).to eq(::Diff)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "define Diffable as Diffable" do
|
|
23
|
-
expect(Invoca::Utils::Diffable).to eq(::Diffable)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "when Diff is defined in the global namespace" do
|
|
27
|
-
before do
|
|
28
|
-
@class = Class.new
|
|
29
|
-
set_test_const("Diff", @class)
|
|
30
|
-
load 'invoca/utils.rb'
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "define Diff as Invoca::Utils::Diff" do
|
|
34
|
-
expect(Invoca::Utils::Diff).to eq(::Diff)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "still allows access to diff-lcs methods" do
|
|
38
|
-
expect(defined?(Diff::LCS)).to eq("constant")
|
|
39
|
-
expect(Diff::LCS).to respond_to(:diff)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "when Diffable is defined in the global namespace" do
|
|
44
|
-
before do
|
|
45
|
-
@class = Class.new
|
|
46
|
-
set_test_const("Diffable", @class)
|
|
47
|
-
load 'invoca/utils.rb'
|
|
48
|
-
end
|
|
6
|
+
it "does not define Diff in the global namespace" do
|
|
7
|
+
expect(Object.const_defined?(:Diff)).to be(false)
|
|
8
|
+
end
|
|
49
9
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
end
|
|
10
|
+
it "does not define Diffable in the global namespace" do
|
|
11
|
+
expect(Object.const_defined?(:Diffable)).to be(false)
|
|
54
12
|
end
|
|
55
13
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: invoca-utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0.colin.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Invoca development
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -24,20 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '6.0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: diff-lcs
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.6.1
|
|
34
|
-
type: :runtime
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: 1.6.1
|
|
41
26
|
description: A public collection of helpers used in multiple projects
|
|
42
27
|
email:
|
|
43
28
|
- development@invoca.com
|
|
@@ -81,9 +66,9 @@ files:
|
|
|
81
66
|
- lib/invoca/utils/stable_sort.rb
|
|
82
67
|
- lib/invoca/utils/time.rb
|
|
83
68
|
- lib/invoca/utils/version.rb
|
|
84
|
-
- spec/helpers/constant_overrides.rb
|
|
85
69
|
- spec/spec_helper.rb
|
|
86
70
|
- spec/unit/array_spec.rb
|
|
71
|
+
- spec/unit/diff_spec.rb
|
|
87
72
|
- spec/unit/enumerable_spec.rb
|
|
88
73
|
- spec/unit/exceptions_spec.rb
|
|
89
74
|
- spec/unit/guaranteed_utf8_string_spec.rb
|
|
@@ -100,7 +85,6 @@ licenses:
|
|
|
100
85
|
- MIT
|
|
101
86
|
metadata:
|
|
102
87
|
allowed_push_host: https://rubygems.org
|
|
103
|
-
post_install_message:
|
|
104
88
|
rdoc_options: []
|
|
105
89
|
require_paths:
|
|
106
90
|
- lib
|
|
@@ -115,14 +99,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
115
99
|
- !ruby/object:Gem::Version
|
|
116
100
|
version: '0'
|
|
117
101
|
requirements: []
|
|
118
|
-
rubygems_version: 3.
|
|
119
|
-
signing_key:
|
|
102
|
+
rubygems_version: 3.6.8
|
|
120
103
|
specification_version: 4
|
|
121
104
|
summary: A public collection of helpers used in multiple projects
|
|
122
105
|
test_files:
|
|
123
|
-
- spec/helpers/constant_overrides.rb
|
|
124
106
|
- spec/spec_helper.rb
|
|
125
107
|
- spec/unit/array_spec.rb
|
|
108
|
+
- spec/unit/diff_spec.rb
|
|
126
109
|
- spec/unit/enumerable_spec.rb
|
|
127
110
|
- spec/unit/exceptions_spec.rb
|
|
128
111
|
- spec/unit/guaranteed_utf8_string_spec.rb
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# The same as https://github.com/Invoca/test_overrides/blob/master/lib/constant_overrides.rb,
|
|
4
|
-
# but less coupled to ExceptionHandling and Invoca microservices.
|
|
5
|
-
|
|
6
|
-
module ConstantOverrides
|
|
7
|
-
def setup_constant_overrides
|
|
8
|
-
@constant_overrides = []
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def cleanup_constant_overrides
|
|
12
|
-
@constant_overrides.reverse.each do |parent_module, k, v|
|
|
13
|
-
silence_warnings do
|
|
14
|
-
if v == :never_defined
|
|
15
|
-
parent_module.send(:remove_const, k)
|
|
16
|
-
else
|
|
17
|
-
parent_module.const_set(k, v)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def set_test_const(const_name, value)
|
|
24
|
-
const_name.is_a?(Symbol) and (const_name = const_name.to_s)
|
|
25
|
-
const_name.is_a?(String) or raise "Pass the constant name, not its value!"
|
|
26
|
-
|
|
27
|
-
final_parent_module = final_const_name = nil
|
|
28
|
-
original_value =
|
|
29
|
-
const_name.split('::').reduce(Object) do |parent_module, nested_const_name|
|
|
30
|
-
parent_module == :never_defined and raise "You need to set each parent constant earlier! #{nested_const_name}"
|
|
31
|
-
final_parent_module = parent_module
|
|
32
|
-
final_const_name = nested_const_name
|
|
33
|
-
begin
|
|
34
|
-
parent_module.const_get(nested_const_name)
|
|
35
|
-
rescue
|
|
36
|
-
:never_defined
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
@constant_overrides << [final_parent_module, final_const_name, original_value]
|
|
41
|
-
|
|
42
|
-
silence_warnings { final_parent_module.const_set(final_const_name, value) }
|
|
43
|
-
end
|
|
44
|
-
end
|