json-schema-diff 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 114ad725bbe219e05ad01ecbb7f419cf47a9d6e0e0861a3f65259ffe5ba08954
4
- data.tar.gz: 34aa2c647ac5e9b6443788328af81dc8b26143641891e34d53b7cd732e711eb2
3
+ metadata.gz: 5fdcc51e044c305681f029f2a2cb6c4d5cd94bd1d365b03f2d9d5a9c8d10af92
4
+ data.tar.gz: 1756f0add39577e56a580217e23af84f85577af1377aaa43767202ade1aba638
5
5
  SHA512:
6
- metadata.gz: a26c6bd182618f38904058a803235b897257263fb012074fb609ba5c11b00835809cdf13fe1e0f963a00a5fb555c9a3cbd5eaebe8d41a43cb976deea839eefdf
7
- data.tar.gz: c657e645bcbe47ad82a46c527b09a0013838569f807674b66af106c5b94ffebdb4b100b3573c4727354240e2b1b1b430601d77de8308bfec5266cfe69b70c7ca
6
+ metadata.gz: c30871c0d847945072f3038f358482131ccc4ca146e0391753e7ff14e107bdf4744988148cbbfe1a64330ae9ac3ad8405aca5c7de87d45a06414735b887c2371
7
+ data.tar.gz: e827e13873598a337d2337c0039514e8f4db86485d029532bf82586f64aeac0e57df9f2694a7af3d5f2c6ec167d538d31f2dd8fc5a5b0418f0941f9a2d1e8f94
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.2] - 2025-10-15
11
+
12
+ ### Added
13
+
14
+ - Support for ignoring fields using regular expression patterns (contributed by @icnagy in #1)
15
+
10
16
  ## [0.2.1] - 2025-01-26
11
17
 
12
18
  ### Added
data/README.md CHANGED
@@ -159,6 +159,16 @@ formatter = Json::Schema::Diff::Formatter.new('pretty', true)
159
159
  puts formatter.format(changes)
160
160
  ```
161
161
 
162
+ #### Ignoring fields using regular expression
163
+
164
+ Fields can be ignored by using regular expressions:
165
+
166
+ ```ruby
167
+ comparer = Json::Schema::Diff::Comparer.new(schema, [%r{List\[.*\]\.field}])
168
+ ```
169
+
170
+ This can be helpful when the field to be ignored is embedded in a list.
171
+
162
172
  ## Schema Features
163
173
 
164
174
  ### Supported JSON Schema Properties
@@ -11,10 +11,10 @@ module Json
11
11
  # Initialize a new Comparer
12
12
  #
13
13
  # @param schema_parser [SchemaParser] Parser for the JSON Schema
14
- # @param ignore_fields [Array<String>] List of field paths to ignore during comparison
14
+ # @param ignore_fields [Array<String|Regexp>] List of field paths and patterns to ignore during comparison
15
15
  def initialize(schema_parser, ignore_fields = [])
16
16
  @schema_parser = schema_parser
17
- @ignore_fields = ignore_fields.map(&:to_s)
17
+ @ignore_fields = ignore_fields
18
18
  end
19
19
 
20
20
  # Compares two JSON objects and returns a list of changes
@@ -30,9 +30,23 @@ module Json
30
30
 
31
31
  private
32
32
 
33
+ def ignored?(path)
34
+ @ignore_fields
35
+ .any? { |pattern| matching?(path, pattern) }
36
+ end
37
+
38
+ def matching?(path, pattern)
39
+ case pattern
40
+ when Regexp
41
+ pattern.match?(path)
42
+ else
43
+ path == pattern
44
+ end
45
+ end
46
+
33
47
  def compare_recursive(old_val, new_val, path, changes)
34
48
  # Skip ignored fields
35
- return if @ignore_fields.include?(path)
49
+ return if ignored?(path)
36
50
 
37
51
  field_info = @schema_parser.get_field_info(path)
38
52
 
@@ -3,7 +3,7 @@
3
3
  module Json
4
4
  module Schema
5
5
  module Diff
6
- VERSION = "0.2.1"
6
+ VERSION = "0.2.2"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt