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 +4 -4
- data/lib/fast_schema_dumper/fast_dumper.rb +17 -1
- data/lib/fast_schema_dumper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e74649c95b51a718a9e5d2d4583adb0eeaa752f72116e4a21235e94b7aed768
|
|
4
|
+
data.tar.gz: b17d033b4449cd527eed2b50ab3c5b5851eca822c9329fd8d698d98733bb50e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|