fast_schema_dumper 0.3.0 → 0.4.0

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: c7ef2b48990a434194a1ac9ddd7394fbef2a5ad40befb705209ccf01edb19c4a
4
- data.tar.gz: 6360a00616008fea6f45913597ce0fc9ebbca688243bb1a204fb0abb33922ea7
3
+ metadata.gz: 9e74649c95b51a718a9e5d2d4583adb0eeaa752f72116e4a21235e94b7aed768
4
+ data.tar.gz: b17d033b4449cd527eed2b50ab3c5b5851eca822c9329fd8d698d98733bb50e9
5
5
  SHA512:
6
- metadata.gz: 6a701f24b8eacb312ad56c60c96edd12aa795fa27ecf8e59e511455e55ff36efca84e6ecb9598d7ec197c0f3120a33fd487f3b1d59d34098cf469637c37aec85
7
- data.tar.gz: 06cd91e908371c31c24bf90ba9d21c8f359d8a0007ceb2698a7e5712280bf191d010edf90360c72b2975b72d8df7a001bf1776591d4c23b1d9a0252301bd307c
6
+ metadata.gz: 8a94ed1a0bf13a02910a3a7a69f154dc1d5f5926d6bdeafedd5a241855052e6d03507825ad9cf93d2788f59a2ca19e031fd81a370fca578d4b88deed5c9db4fb
7
+ data.tar.gz: 53b42423236881b8887180819cee487cad61d90433750a18f5759059dd87dc1460fc98314d512c1f48d451e3d9da284b2e5e7429410d956ccd21b68781a21582
@@ -338,8 +338,14 @@ module FastSchemaDumper
338
338
  check_clause = constraint[:check_clause]
339
339
 
340
340
  # drop redundant parentheses at the most outer level for compatibility with the original dumper
341
+ # Example: "((a > 0) and (b > 0))" => "(a > 0) and (b > 0)"
341
342
  if check_clause.start_with?("(") && check_clause.end_with?(")")
342
- check_clause = check_clause[1..-2]
343
+ # Check if removing outer parens would break the expression by ensuring parentheses are balanced after removal
344
+ # For example, it shouldn’t remove the outer parentheses as in the following case, because doing so would break the balance: "(a > 0) and (b > 0)"
345
+ inner = check_clause[1..-2]
346
+ if balanced_parentheses?(inner)
347
+ check_clause = inner
348
+ end
343
349
  end
344
350
 
345
351
  check_clause.gsub!(/\\'/, "'") # don't escape single quotes for compatibility with the original dumper
@@ -525,5 +531,15 @@ module FastSchemaDumper
525
531
 
526
532
  idx_def
527
533
  end
534
+
535
+ def balanced_parentheses?(str)
536
+ depth = 0
537
+ str.each_char do |char|
538
+ depth += 1 if char == '('
539
+ depth -= 1 if char == ')'
540
+ return false if depth < 0
541
+ end
542
+ depth == 0
543
+ end
528
544
  end
529
545
  end
@@ -1,3 +1,3 @@
1
1
  module FastSchemaDumper
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_schema_dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Aritomo