code-ruby 5.2.3 → 5.2.4
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/VERSION +1 -1
- data/lib/code/format.rb +22 -3
- data/lib/code/object/string.rb +3 -1
- data/lib/code/parser.rb +6 -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: b2db565dfb611ea14df67af826fd2a7d425c4994a355fb2dea00f768263af06a
|
|
4
|
+
data.tar.gz: e227c3acd9a1f6bdbc1f60f1a3229266d1d48b3a850e3a9066275c9613057ad5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc5764588753a879e2fcc926e16e8a86895964192f15a692c941fcdc8fa6dfd578ebcd1eff3214d91ca82bc7dbaab0687866d3778bcdb5bd65fa37f8bdb2e190
|
|
7
|
+
data.tar.gz: 190d3f87a380bd783ba276f1b82935f740f0d5b3be52d3d44c5a6f728e7e95f0448df8a1f37734a5ea71c1f2ff0f3cc33e373155e3f6eaac6fafd770cf3ee07d
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.2.
|
|
1
|
+
5.2.4
|
data/lib/code/format.rb
CHANGED
|
@@ -201,7 +201,7 @@ class Code
|
|
|
201
201
|
return nil unless node.is_a?(Hash) && node.key?(:text)
|
|
202
202
|
|
|
203
203
|
text = node[:text].to_s
|
|
204
|
-
return nil unless text.match?(/\A[a-z_][a-z0-9_]
|
|
204
|
+
return nil unless text.match?(/\A[a-z_][a-z0-9_]*[?!]?\z/)
|
|
205
205
|
|
|
206
206
|
":#{text}"
|
|
207
207
|
end
|
|
@@ -349,7 +349,7 @@ class Code
|
|
|
349
349
|
return unless part.is_a?(Hash) && part.key?(:text)
|
|
350
350
|
|
|
351
351
|
text = part[:text].to_s
|
|
352
|
-
return unless text.match?(/\A[a-z_][a-z0-9_]
|
|
352
|
+
return unless text.match?(/\A[a-z_][a-z0-9_]*[?!]?\z/)
|
|
353
353
|
|
|
354
354
|
text
|
|
355
355
|
end
|
|
@@ -464,7 +464,11 @@ class Code
|
|
|
464
464
|
|
|
465
465
|
Array(operation[:others]).each do |other|
|
|
466
466
|
operator = format_operator(other[:operator])
|
|
467
|
-
right =
|
|
467
|
+
right = if compact_operator?(operator)
|
|
468
|
+
format_member_statement(other[:statement], indent: indent)
|
|
469
|
+
else
|
|
470
|
+
format_boolean_operand(other[:statement], operator, indent: indent)
|
|
471
|
+
end
|
|
468
472
|
|
|
469
473
|
expression =
|
|
470
474
|
if compact_operator?(operator)
|
|
@@ -511,6 +515,21 @@ class Code
|
|
|
511
515
|
expression
|
|
512
516
|
end
|
|
513
517
|
|
|
518
|
+
def format_member_statement(statement, indent:)
|
|
519
|
+
if statement.is_a?(Hash) && statement[:call] && (statement[:call][:arguments] || []).empty?
|
|
520
|
+
format_call(statement[:call].except(:arguments), indent: indent)
|
|
521
|
+
elsif statement.is_a?(Hash) && statement[:left_operation]
|
|
522
|
+
operation = statement[:left_operation].deep_dup
|
|
523
|
+
first = operation[:first]
|
|
524
|
+
if first[:call] && (first[:call][:arguments] || []).empty?
|
|
525
|
+
first[:call].delete(:arguments)
|
|
526
|
+
end
|
|
527
|
+
format_left_operation(operation, indent: indent)
|
|
528
|
+
else
|
|
529
|
+
format_nested_statement(statement, indent: indent)
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
|
|
514
533
|
def format_boolean_operand(statement, operator, indent:)
|
|
515
534
|
if BOOLEAN_WORD_OPERATORS.include?(operator) && statement.is_a?(Hash) &&
|
|
516
535
|
statement[:left_operation]
|
data/lib/code/object/string.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
class Code
|
|
4
4
|
class Object
|
|
5
5
|
class String < Object
|
|
6
|
+
DEFAULT_OMISSION = "…"
|
|
7
|
+
|
|
6
8
|
CLASS_DOCUMENTATION = {
|
|
7
9
|
name: "String",
|
|
8
10
|
description:
|
|
@@ -1224,7 +1226,7 @@ class Code
|
|
|
1224
1226
|
def code_truncate(limit, options = nil)
|
|
1225
1227
|
limit = limit.to_code.raw
|
|
1226
1228
|
omission = options.to_code.code_get("omission")
|
|
1227
|
-
omission = omission.nothing? ?
|
|
1229
|
+
omission = omission.nothing? ? DEFAULT_OMISSION : omission.to_s
|
|
1228
1230
|
if limit < omission.length
|
|
1229
1231
|
raise ::Code::Error, "invalid truncation limit"
|
|
1230
1232
|
end
|
data/lib/code/parser.rb
CHANGED
|
@@ -523,7 +523,12 @@ class Code
|
|
|
523
523
|
if match?(:punctuation, ":") || match?(:operator, "=>")
|
|
524
524
|
advance
|
|
525
525
|
code = parse_optional_code(%w[, }])
|
|
526
|
-
|
|
526
|
+
parts = statement[:string]
|
|
527
|
+
if parts&.one? && parts.first[:text]&.match?(/\A[a-z_][a-z0-9_]*[?!]?\z/)
|
|
528
|
+
{ name_code: { name: parts.first[:text], code: code }.compact }
|
|
529
|
+
else
|
|
530
|
+
{ statement_code: { statement: statement, code: code }.compact }
|
|
531
|
+
end
|
|
527
532
|
else
|
|
528
533
|
{ code: wrap_code(statement) }
|
|
529
534
|
end
|