hash_diff 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/codeql.yml +59 -0
- data/.github/workflows/ruby.yml +25 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/README.md +3 -1
- data/hash_diff.gemspec +3 -3
- data/lib/hash_diff/comparison.rb +20 -3
- data/lib/hash_diff/version.rb +1 -1
- data/spec/hash_diff/array_comparison_spec.rb +78 -0
- metadata +18 -13
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ef02ebe0aac07af77b8e597a40b218c4b2f20c53f3f895fc131d07961a38011
|
4
|
+
data.tar.gz: 7b03cd799b1f0a5eded66d91d5ed0f9b882ef38e26fec1c004568d71e5e68d0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e29131dc0ebf4b1e61997526c45ec123ac1ad3fa1f6182bd147e45586d4caa251ae113ebd7273efb5a107207ae6733688be1d3eb43712d1d79547754ceec13c
|
7
|
+
data.tar.gz: d37b0e72862bdb28550c8b481bdf03e377b7e2e20473b4111f444bc3c19f3402d1cd4eba0b92b1c22083ad1b211760f84c204c40247a08b37be6f50a928b6e64
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
2
|
+
version: 2
|
3
|
+
updates:
|
4
|
+
- package-ecosystem: "bundler"
|
5
|
+
directory: "/" # Location of package manifests
|
6
|
+
schedule:
|
7
|
+
interval: "monthly"
|
8
|
+
|
9
|
+
- package-ecosystem: "github-actions"
|
10
|
+
directory: "/"
|
11
|
+
schedule:
|
12
|
+
interval: "monthly"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
name: "CodeQL"
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
# The branches below must be a subset of the branches above
|
8
|
+
branches: [ master ]
|
9
|
+
schedule:
|
10
|
+
- cron: '39 15 * * 4'
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
analyze:
|
14
|
+
name: Analyze
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
permissions:
|
17
|
+
actions: read
|
18
|
+
contents: read
|
19
|
+
security-events: write
|
20
|
+
|
21
|
+
strategy:
|
22
|
+
fail-fast: false
|
23
|
+
matrix:
|
24
|
+
language: [ 'ruby' ]
|
25
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
26
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
27
|
+
|
28
|
+
steps:
|
29
|
+
- name: Checkout repository
|
30
|
+
uses: actions/checkout@v3
|
31
|
+
|
32
|
+
# Initializes the CodeQL tools for scanning.
|
33
|
+
- name: Initialize CodeQL
|
34
|
+
uses: github/codeql-action/init@v2
|
35
|
+
with:
|
36
|
+
languages: ${{ matrix.language }}
|
37
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
38
|
+
# By default, queries listed here will override any specified in a config file.
|
39
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
40
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
41
|
+
|
42
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
43
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
44
|
+
- name: Autobuild
|
45
|
+
uses: github/codeql-action/autobuild@v2
|
46
|
+
|
47
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
48
|
+
# 📚 https://git.io/JvXDl
|
49
|
+
|
50
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
51
|
+
# and modify them (or add more) to build your code if your project
|
52
|
+
# uses a compiled language
|
53
|
+
|
54
|
+
#- run: |
|
55
|
+
# make bootstrap
|
56
|
+
# make release
|
57
|
+
|
58
|
+
- name: Perform CodeQL Analysis
|
59
|
+
uses: github/codeql-action/analyze@v2
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby-version: ['1.9', '2.0', '2.1', '2.2', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
- name: Set up Ruby
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
23
|
+
bundler-cache: true
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# HashDiff
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Ruby](https://github.com/CodingZeal/hash_diff/actions/workflows/ruby.yml/badge.svg)](https://github.com/CodingZeal/hash_diff/actions/workflows/ruby.yml) [![Code Climate](https://codeclimate.com/github/CodingZeal/hash_diff.png)](https://codeclimate.com/github/CodingZeal/hash_diff) [![Gem Version](https://badge.fury.io/rb/hash_diff.png)](http://badge.fury.io/rb/hash_diff)
|
4
4
|
|
5
5
|
Deep comparison of Ruby Hash objects
|
6
6
|
|
@@ -58,6 +58,8 @@ Comparison#diff returns the left and right side differences
|
|
58
58
|
hash_diff.diff # => { foo: ["bar", "bar2"], bar: ["foo", "foo2"], nested: { foo: ["bar", "bar2"], bar: { one: ["foo1", HashDiff::NO_VALUE], two: [HashDiff::NO_VALUE, "foo2"] } }, num: [1, HashDiff::NO_VALUE], word: [HashDiff::NO_VALUE, "monkey"], favorite_restaurant: ["Shoney's", nil] }
|
59
59
|
```
|
60
60
|
|
61
|
+
You can also compare two arrays. The comparison is sensitive to the order of the elements in the array.
|
62
|
+
|
61
63
|
#### Missing keys
|
62
64
|
|
63
65
|
When there is a key that exists on one side it will return `HashDiff::NO_VALUE` to represent a missing key.
|
data/hash_diff.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'hash_diff/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "hash_diff"
|
8
8
|
spec.version = HashDiff::VERSION
|
9
|
-
spec.authors = ["Coding Zeal", "Adam Cuppy"]
|
10
|
-
spec.email = ["info@codingzeal.com"]
|
9
|
+
spec.authors = ["Coding Zeal", "Adam Cuppy", "Mike Bianco"]
|
10
|
+
spec.email = ["info@codingzeal.com", "mike@mikebian.co"]
|
11
11
|
spec.description = %q{Diff tool for deep Ruby hash comparison}
|
12
12
|
spec.summary = %q{Deep Ruby Hash comparison}
|
13
13
|
spec.homepage = "https://github.com/CodingZeal/hash_diff"
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.1"
|
24
24
|
end
|
data/lib/hash_diff/comparison.rb
CHANGED
@@ -34,7 +34,13 @@ module HashDiff
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def combined_keys
|
37
|
-
(left
|
37
|
+
if hash?(left) && hash?(right) then
|
38
|
+
(left.keys + right.keys).uniq.sort
|
39
|
+
elsif array?(left) && array?(right) then
|
40
|
+
(0..[left.size, right.size].max).to_a
|
41
|
+
else
|
42
|
+
raise ArgumentError, "Don't know how to extract keys. Neither arrays nor hashes given"
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
def equal?(key)
|
@@ -45,12 +51,22 @@ module HashDiff
|
|
45
51
|
value.is_a?(Hash)
|
46
52
|
end
|
47
53
|
|
48
|
-
def
|
54
|
+
def array?(value)
|
55
|
+
value.is_a?(Array)
|
56
|
+
end
|
57
|
+
|
58
|
+
def comparable_hash?(key)
|
49
59
|
hash?(left[key]) && hash?(right[key])
|
50
60
|
end
|
51
61
|
|
62
|
+
def comparable_array?(key)
|
63
|
+
array?(left[key]) && array?(right[key])
|
64
|
+
end
|
65
|
+
|
52
66
|
def report_difference(key, reporter)
|
53
|
-
if
|
67
|
+
if comparable_hash?(key)
|
68
|
+
self.class.new(left[key], right[key]).find_differences(&reporter)
|
69
|
+
elsif comparable_array?(key)
|
54
70
|
self.class.new(left[key], right[key]).find_differences(&reporter)
|
55
71
|
else
|
56
72
|
reporter.call(
|
@@ -65,3 +81,4 @@ module HashDiff
|
|
65
81
|
end
|
66
82
|
end
|
67
83
|
end
|
84
|
+
|
data/lib/hash_diff/version.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe HashDiff::Comparison do
|
4
|
+
let(:left) {
|
5
|
+
[
|
6
|
+
{
|
7
|
+
foo: 'bar',
|
8
|
+
bar: 'foo',
|
9
|
+
},
|
10
|
+
{
|
11
|
+
nested: {
|
12
|
+
foo: 'bar',
|
13
|
+
bar: {
|
14
|
+
one: 'foo1'
|
15
|
+
}
|
16
|
+
},
|
17
|
+
},
|
18
|
+
{
|
19
|
+
num: 1,
|
20
|
+
word: nil
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
|
25
|
+
def comparison(to_compare)
|
26
|
+
HashDiff::Comparison.new(left, to_compare)
|
27
|
+
end
|
28
|
+
|
29
|
+
def right
|
30
|
+
[
|
31
|
+
{
|
32
|
+
foo: 'bar',
|
33
|
+
bar: 'foo',
|
34
|
+
},
|
35
|
+
{
|
36
|
+
nested: {
|
37
|
+
foo: 'bar',
|
38
|
+
bar: {
|
39
|
+
one: 'foo1'
|
40
|
+
}
|
41
|
+
},
|
42
|
+
},
|
43
|
+
{
|
44
|
+
num: 1,
|
45
|
+
word: nil
|
46
|
+
}
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'when arrays are the same' do
|
51
|
+
it 'properly determines equality' do
|
52
|
+
expect(comparison(right).diff).to be_empty
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'handles empty arrays' do
|
56
|
+
expect(HashDiff::Comparison.new([], []).diff).to be_empty
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'when arrays are different' do
|
61
|
+
it 'reports arrays as not equal with a different order' do
|
62
|
+
# move an item from the end to the beginning
|
63
|
+
right_shuffled = right
|
64
|
+
popped = right_shuffled.pop
|
65
|
+
right_shuffled.unshift(popped)
|
66
|
+
|
67
|
+
expect(comparison(right_shuffled).diff).to_not be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should a deep comparison' do
|
71
|
+
right_with_extra_nested_element = right
|
72
|
+
right_with_extra_nested_element[1][:nested][:bar][:two] = 'two'
|
73
|
+
|
74
|
+
expect(comparison(right_with_extra_nested_element).diff).to_not be_empty
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Coding Zeal
|
8
8
|
- Adam Cuppy
|
9
|
-
|
9
|
+
- Mike Bianco
|
10
|
+
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: bundler
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
18
|
requirements:
|
18
|
-
- - "
|
19
|
+
- - ">="
|
19
20
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
21
|
+
version: '0'
|
21
22
|
type: :development
|
22
23
|
prerelease: false
|
23
24
|
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
|
-
- - "
|
26
|
+
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
28
|
+
version: '0'
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
30
|
name: rake
|
30
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,12 +57,16 @@ dependencies:
|
|
56
57
|
description: Diff tool for deep Ruby hash comparison
|
57
58
|
email:
|
58
59
|
- info@codingzeal.com
|
60
|
+
- mike@mikebian.co
|
59
61
|
executables: []
|
60
62
|
extensions: []
|
61
63
|
extra_rdoc_files: []
|
62
64
|
files:
|
65
|
+
- ".github/dependabot.yml"
|
66
|
+
- ".github/workflows/codeql.yml"
|
67
|
+
- ".github/workflows/ruby.yml"
|
63
68
|
- ".gitignore"
|
64
|
-
- ".
|
69
|
+
- ".ruby-version"
|
65
70
|
- Gemfile
|
66
71
|
- LICENSE.txt
|
67
72
|
- README.md
|
@@ -70,6 +75,7 @@ files:
|
|
70
75
|
- lib/hash_diff.rb
|
71
76
|
- lib/hash_diff/comparison.rb
|
72
77
|
- lib/hash_diff/version.rb
|
78
|
+
- spec/hash_diff/array_comparison_spec.rb
|
73
79
|
- spec/hash_diff/comparison_spec.rb
|
74
80
|
- spec/hash_diff_spec.rb
|
75
81
|
- spec/spec_helper.rb
|
@@ -77,7 +83,7 @@ homepage: https://github.com/CodingZeal/hash_diff
|
|
77
83
|
licenses:
|
78
84
|
- MIT
|
79
85
|
metadata: {}
|
80
|
-
post_install_message:
|
86
|
+
post_install_message:
|
81
87
|
rdoc_options: []
|
82
88
|
require_paths:
|
83
89
|
- lib
|
@@ -92,13 +98,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
98
|
- !ruby/object:Gem::Version
|
93
99
|
version: '0'
|
94
100
|
requirements: []
|
95
|
-
|
96
|
-
|
97
|
-
signing_key:
|
101
|
+
rubygems_version: 3.1.6
|
102
|
+
signing_key:
|
98
103
|
specification_version: 4
|
99
104
|
summary: Deep Ruby Hash comparison
|
100
105
|
test_files:
|
106
|
+
- spec/hash_diff/array_comparison_spec.rb
|
101
107
|
- spec/hash_diff/comparison_spec.rb
|
102
108
|
- spec/hash_diff_spec.rb
|
103
109
|
- spec/spec_helper.rb
|
104
|
-
has_rdoc:
|