hashdiff 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9b50073f973250c144bb05272510f462dda18a7f5c9a8719156065773fdcaaa
4
- data.tar.gz: 903439ed3ea22994d072201509506232fb77482506494bbb8c8419dc9fb8d546
3
+ metadata.gz: 56a70b8fb995b7d778a1840400c42303c34648a9205055b11157a5b69208afa1
4
+ data.tar.gz: 410e1bea7bc27e43f4580c42ff17054e1ce57dc3c3f486fe570269e366c7ecb4
5
5
  SHA512:
6
- metadata.gz: e1c00d4710a67688a35197197da93ac3bfabca5f5a51edc152bfbd341a16548e762ddf2290364b7fc3a20e99cdb6d8d909ff84e766468fe623eb3977afd6d90f
7
- data.tar.gz: 2d860929e99458cd89ee60ce877a87557d6bb9d52dcd25e0989f1a0a7b372d026bb646ee2b19498f6637a485f15fcd1e68cf1e1c0dbe666ad5af1792d60a893a
6
+ metadata.gz: 30e90e14ee676c7b035a20d01f5f8cf5dfcdae7319f652bd828c6fcc8d66a4e6b0cb8fd046937ce09a38aac8e7c3eba92dfc60b8ea2e09674eb9c8ea35256e9a
7
+ data.tar.gz: 146cc4564d22ee6c6ef47b09032e4e171cd2682ecd941e798bd729bea7d3e8a10974356e39500886bd6ec4d0d3d6c109d2e6556bbe47abc7b79a9c9d45db66e4
data/.rubocop.yml CHANGED
@@ -17,16 +17,24 @@ Metrics/BlockLength:
17
17
  Enabled: false
18
18
  Metrics/ModuleLength:
19
19
  Enabled: false
20
+ Style/CaseLikeIf:
21
+ Enabled: false
20
22
  Style/Documentation:
21
23
  Enabled: false
22
24
  Style/FrozenStringLiteralComment:
23
25
  Enabled: true
24
26
  EnforcedStyle: always
27
+ Style/OptionalBooleanParameter:
28
+ Enabled: false
25
29
  Style/NumericPredicate:
26
30
  Enabled: false
27
31
  Style/RedundantFreeze:
28
32
  Enabled: false
33
+ Style/RedundantReturn:
34
+ Enabled: false
29
35
  RSpec/ExampleLength:
30
36
  Enabled: false
31
37
  RSpec/DescribeClass:
32
38
  Enabled: false
39
+ RSpec/FilePath:
40
+ Enabled: false
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source 'http://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'rake', '< 11'
7
+ gem 'rake'
8
8
  end
data/README.md CHANGED
@@ -94,9 +94,8 @@ Hashdiff.unpatch!(b, diff).should == a
94
94
 
95
95
  ### Options
96
96
 
97
- There are eight options available: `:delimiter`, `:similarity`,
98
- `:strict`, `:indifferent`, `:numeric_tolerance`, `:strip`, `:case_insensitive`,
99
- `:array_path` and `:use_lcs`
97
+ The following options are available: `:delimiter`, `:similarity`, `:strict`, `:ignore_keys`,
98
+ `:indifferent`, `:numeric_tolerance`, `:strip`, `:case_insensitive`, `:array_path` and `:use_lcs`
100
99
 
101
100
  #### `:delimiter`
102
101
 
@@ -118,6 +117,26 @@ In cases where you have similar hash objects in arrays, you can pass a custom va
118
117
 
119
118
  The `:strict` option, which defaults to `true`, specifies whether numeric types are compared on type as well as value. By default, an Integer will never be equal to a Float (e.g. 4 != 4.0). Setting `:strict` to false makes the comparison looser (e.g. 4 == 4.0).
120
119
 
120
+ #### `:ignore_keys`
121
+
122
+ The `:ignore_keys` option allows you to specify one or more keys to ignore, which defaults to `[]` (none). Ignored keys are ignored at all levels. For example:
123
+
124
+ ```ruby
125
+ a = { a: 1, b: { d: 2, a: 3 }, c: 4 }
126
+ b = { a: 2, b: { d: 2, a: 7 }, c: 5 }
127
+ diff = Hashdiff.diff(a, b, ignore_keys: :a)
128
+ diff.should == [['~', 'c', 4, 5]]
129
+ ```
130
+ If you wish instead to ignore keys at a particlar level you should
131
+ use a [custom comparison method](https://github.com/liufengyun/hashdiff#specifying-a-custom-comparison-method) instead. For example:
132
+
133
+ ```ruby
134
+ a = { a: 1, b: { d: 2, a: 3 }, c: 4 }
135
+ b = { a: 2, b: { d: 2, a: 7 }, c: 5 }
136
+ diff = Hashdiff.diff(a, b) { |path, _e, _a| true if path == 'b.a' } # note '.' is the default delimiter
137
+ diff.should == [['~', 'a', 1, 2], ['~', 'c', 4, 5]]
138
+ ```
139
+
121
140
  #### `:indifferent`
122
141
 
123
142
  The `:indifferent` option, which defaults to `false`, specifies whether to treat hash keys indifferently. Setting `:indifferent` to true has the effect of ignoring differences between symbol keys (ie. {a: 1} ~= {'a' => 1})
data/changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## v1.1.0 2020-02-25
4
+
5
+ * Add ignore_keys option (#86 @Matzfan)
6
+ * Remove pinned version of rake < 11
7
+ * Bump rspec dep ~> 3.5
8
+ * Bump rubocop dep >= 1.52.1
9
+ * Bump rubocop-rspec dep > 1.16.0
10
+
3
11
  ## v1.0.1 2020-02-25
4
12
 
5
13
  * Add indifferent option
data/hashdiff.gemspec CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |s|
22
22
  s.homepage = 'https://github.com/liufengyun/hashdiff'
23
23
 
24
24
  s.add_development_dependency('bluecloth')
25
- s.add_development_dependency('rspec', '~> 2.0')
26
- s.add_development_dependency('rubocop', '~> 0.49.1') # last version that works with ruby 2.0
27
- s.add_development_dependency('rubocop-rspec')
25
+ s.add_development_dependency('rspec', '~> 3.5')
26
+ s.add_development_dependency('rubocop', '>= 1.52.1') # earliest version that works with Ruby 3.3
27
+ s.add_development_dependency('rubocop-rspec', '> 1.16.0') # https://github.com/rubocop/rubocop-rspec/issues/461
28
28
  s.add_development_dependency('yard')
29
29
 
30
30
  if s.respond_to?(:metadata)
@@ -26,6 +26,8 @@ module Hashdiff
26
26
 
27
27
  result = []
28
28
 
29
+ opts[:ignore_keys].each { |k| common_keys.delete k }
30
+
29
31
  # add deleted properties
30
32
  deleted_keys.each do |k|
31
33
  k = opts[:indifferent] ? obj1_lookup[k] : k
data/lib/hashdiff/diff.rb CHANGED
@@ -9,6 +9,7 @@ module Hashdiff
9
9
  # @param [Array, Hash] obj2
10
10
  # @param [Hash] options the options to use when comparing
11
11
  # * :strict (Boolean) [true] whether numeric values will be compared on type as well as value. Set to false to allow comparing Integer, Float, BigDecimal to each other
12
+ # * :ignore_keys (Symbol, String or Array) [[]] a list of keys to ignore. No comparison is made for the specified key(s)
12
13
  # * :indifferent (Boolean) [false] whether to treat hash keys indifferently. Set to true to ignore differences between symbol keys (ie. {a: 1} ~= {'a' => 1})
13
14
  # * :delimiter (String) ['.'] the delimiter used when returning nested key references
14
15
  # * :numeric_tolerance (Numeric) [0] should be a positive numeric value. Value by which numeric differences must be greater than. By default, numeric values are compared exactly; with the :tolerance option, the difference between numeric values must be greater than the given value.
@@ -53,6 +54,7 @@ module Hashdiff
53
54
  # @param [Array, Hash] obj2
54
55
  # @param [Hash] options the options to use when comparing
55
56
  # * :strict (Boolean) [true] whether numeric values will be compared on type as well as value. Set to false to allow comparing Integer, Float, BigDecimal to each other
57
+ # * :ignore_keys (Symbol, String or Array) [[]] a list of keys to ignore. No comparison is made for the specified key(s)
56
58
  # * :indifferent (Boolean) [false] whether to treat hash keys indifferently. Set to true to ignore differences between symbol keys (ie. {a: 1} ~= {'a' => 1})
57
59
  # * :similarity (Numeric) [0.8] should be between (0, 1]. Meaningful if there are similar hashes in arrays. See {best_diff}.
58
60
  # * :delimiter (String) ['.'] the delimiter used when returning nested key references
@@ -81,6 +83,7 @@ module Hashdiff
81
83
  similarity: 0.8,
82
84
  delimiter: '.',
83
85
  strict: true,
86
+ ignore_keys: [],
84
87
  indifferent: false,
85
88
  strip: false,
86
89
  numeric_tolerance: 0,
@@ -90,6 +93,8 @@ module Hashdiff
90
93
 
91
94
  opts[:prefix] = [] if opts[:array_path] && opts[:prefix] == ''
92
95
 
96
+ opts[:ignore_keys] = [*opts[:ignore_keys]] # splat covers single sym/string case
97
+
93
98
  opts[:comparison] = block if block_given?
94
99
 
95
100
  # prefer to compare with provided block
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hashdiff
4
- VERSION = '1.0.1'.freeze
4
+ VERSION = '1.1.0'.freeze
5
5
  end
@@ -49,6 +49,21 @@ describe Hashdiff do
49
49
  diff.should == []
50
50
  end
51
51
 
52
+ context 'with the ignore_keys option' do
53
+ a = { a: 1, b: { d: 2, a: 3 }, c: 4 }
54
+ b = { a: 2, b: { d: 2, a: 7 }, c: 5 }
55
+
56
+ it 'ignores a single key' do
57
+ diff = described_class.diff(a, b, ignore_keys: :a)
58
+ diff.should == [['~', 'c', 4, 5]]
59
+ end
60
+
61
+ it 'ignores an array of keys' do
62
+ diff = described_class.diff(a, b, ignore_keys: %i[a c])
63
+ diff.should == []
64
+ end
65
+ end
66
+
52
67
  it 'ignores string vs symbol differences, when indifferent is true' do
53
68
  diff = described_class.diff({ 'a' => 2, :b => 2 }, { :a => 2, 'b' => 2, :c => 3 }, indifferent: true)
54
69
  diff.should == [['+', 'c', 3]]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Fengyun
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-27 00:00:00.000000000 Z
11
+ date: 2023-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bluecloth
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '3.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.49.1
47
+ version: 1.52.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.49.1
54
+ version: 1.52.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ">"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.16.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ">"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.16.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +126,7 @@ metadata:
126
126
  documentation_uri: https://www.rubydoc.info/gems/hashdiff
127
127
  homepage_uri: https://github.com/liufengyun/hashdiff
128
128
  source_code_uri: https://github.com/liufengyun/hashdiff
129
- post_install_message:
129
+ post_install_message:
130
130
  rdoc_options: []
131
131
  require_paths:
132
132
  - lib
@@ -141,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.0.6
145
- signing_key:
144
+ rubygems_version: 3.4.10
145
+ signing_key:
146
146
  specification_version: 4
147
147
  summary: Hashdiff is a diff lib to compute the smallest difference between two hashes.
148
148
  test_files: []