code-ruby 4.0.0 → 4.0.1

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.
@@ -5,7 +5,8 @@ class Code
5
5
  class Url < Object
6
6
  CLASS_DOCUMENTATION = {
7
7
  name: "Url",
8
- description: "encodes text for urls, decodes url-escaped text, and parses strings as urls.",
8
+ description:
9
+ "encodes text for urls, decodes url-escaped text, and parses strings as urls.",
9
10
  examples: [
10
11
  "Url.encode(\"hello world\")",
11
12
  "Url.decode(\"a%2Fb%3Fx%3D1\")",
@@ -33,7 +34,8 @@ class Code
33
34
  },
34
35
  "parse" => {
35
36
  name: "parse",
36
- description: "returns a url parsed from a value, or an empty url when parsing fails.",
37
+ description:
38
+ "returns a url parsed from a value, or an empty url when parsing fails.",
37
39
  examples: [
38
40
  "Url.parse(\"https://example.com/a?b=1\")",
39
41
  "Url.parse(\"/path\")",
data/lib/code/object.rb CHANGED
@@ -14,11 +14,7 @@ class Code
14
14
  CLASS_DOCUMENTATION = {
15
15
  name: "Object",
16
16
  description: "provides the shared behavior available to every value.",
17
- examples: [
18
- "Object",
19
- "Object.new",
20
- "Object.documentation.description"
21
- ]
17
+ examples: %w[Object Object.new Object.documentation.description]
22
18
  }.freeze
23
19
  INSTANCE_FUNCTIONS = {
24
20
  "documentation" => {
@@ -32,7 +28,8 @@ class Code
32
28
  },
33
29
  "functions" => {
34
30
  name: "functions",
35
- description: "returns documented instance and class functions available on the value.",
31
+ description:
32
+ "returns documented instance and class functions available on the value.",
36
33
  examples: [
37
34
  "[].functions.keys.include?(:map)",
38
35
  "1.functions.keys.include?(:to_string)",
@@ -41,7 +38,8 @@ class Code
41
38
  },
42
39
  "instance_functions" => {
43
40
  name: "instance_functions",
44
- description: "returns documented functions available on values of the receiver.",
41
+ description:
42
+ "returns documented functions available on values of the receiver.",
45
43
  examples: [
46
44
  "[].instance_functions.keys.include?(:map)",
47
45
  "1.instance_functions.keys.include?(:to_string)",
@@ -50,7 +48,8 @@ class Code
50
48
  },
51
49
  "class_functions" => {
52
50
  name: "class_functions",
53
- description: "returns documented functions available on the receiver constructor.",
51
+ description:
52
+ "returns documented functions available on the receiver constructor.",
54
53
  examples: [
55
54
  "[].class_functions",
56
55
  "List.class_functions.keys.include?(:new)",
@@ -59,7 +58,8 @@ class Code
59
58
  },
60
59
  "respond_to?" => {
61
60
  name: "respond_to?",
62
- description: "returns whether the value responds to the named function.",
61
+ description:
62
+ "returns whether the value responds to the named function.",
63
63
  examples: [
64
64
  "[].respond_to?(:map)",
65
65
  "1.respond_to?(:zero?)",
@@ -83,7 +83,8 @@ class Code
83
83
  },
84
84
  "presence_in" => {
85
85
  name: "presence_in",
86
- description: "returns the value when it is included in the list, otherwise nothing.",
86
+ description:
87
+ "returns the value when it is included in the list, otherwise nothing.",
87
88
  examples: [
88
89
  "2.presence_in([1, 2, 3])",
89
90
  "4.presence_in([1, 2, 3])",
@@ -92,7 +93,8 @@ class Code
92
93
  },
93
94
  "is_a?" => {
94
95
  name: "is_a?",
95
- description: "returns whether the value is an instance of the class or one of its subclasses.",
96
+ description:
97
+ "returns whether the value is an instance of the class or one of its subclasses.",
96
98
  examples: ["1.is_a?(Integer)", ":a.is_a?(String)", "[].is_a?(List)"]
97
99
  },
98
100
  "is_an?" => {
@@ -103,11 +105,16 @@ class Code
103
105
  "kind_of?" => {
104
106
  name: "kind_of?",
105
107
  description: "alias for is_a?.",
106
- examples: ["1.kind_of?(Integer)", ":a.kind_of?(String)", "[].kind_of?(List)"]
108
+ examples: [
109
+ "1.kind_of?(Integer)",
110
+ ":a.kind_of?(String)",
111
+ "[].kind_of?(List)"
112
+ ]
107
113
  },
108
114
  "instance_of?" => {
109
115
  name: "instance_of?",
110
- description: "returns whether the value is exactly an instance of the class.",
116
+ description:
117
+ "returns whether the value is exactly an instance of the class.",
111
118
  examples: [
112
119
  "1.instance_of?(Integer)",
113
120
  ":a.instance_of?(String)",
@@ -117,36 +124,41 @@ class Code
117
124
  "!" => {
118
125
  name: "!",
119
126
  description: "returns the boolean negation of the value.",
120
- examples: ["!true", "!false", "!nothing"]
127
+ examples: %w[!true !false !nothing]
121
128
  },
122
129
  "not" => {
123
130
  name: "not",
124
131
  description: "returns the boolean negation of the value.",
125
- examples: ["true.not", "false.not", "nothing.not"]
132
+ examples: %w[true.not false.not nothing.not]
126
133
  },
127
134
  "!=" => {
128
135
  name: "!=",
129
- description: "returns whether the value is different from another value.",
136
+ description:
137
+ "returns whether the value is different from another value.",
130
138
  examples: ["1 != 2", ":a != :b", "[1] != [2]"]
131
139
  },
132
140
  "different" => {
133
141
  name: "different",
134
- description: "returns whether the value is different from another value.",
142
+ description:
143
+ "returns whether the value is different from another value.",
135
144
  examples: ["1.different(2)", ":a.different(:b)", "[1].different([2])"]
136
145
  },
137
146
  "&&" => {
138
147
  name: "&&",
139
- description: "returns the other value when the receiver is truthy, otherwise the receiver.",
148
+ description:
149
+ "returns the other value when the receiver is truthy, otherwise the receiver.",
140
150
  examples: ["true && 1", "false && 1", "1 && 2"]
141
151
  },
142
152
  "and" => {
143
153
  name: "and",
144
- description: "returns the other value when the receiver is truthy, otherwise the receiver.",
145
- examples: ["true.and(1)", "false.and(1)", "1.and(2)"]
154
+ description:
155
+ "returns the other value when the receiver is truthy, otherwise the receiver.",
156
+ examples: %w[true.and(1) false.and(1) 1.and(2)]
146
157
  },
147
158
  "+" => {
148
159
  name: "+",
149
- description: "returns the receiver for object types that do not override plus.",
160
+ description:
161
+ "returns the receiver for object types that do not override plus.",
150
162
  examples: ["+Object.new", "+nothing", "+[]"]
151
163
  },
152
164
  "self" => {
@@ -156,30 +168,34 @@ class Code
156
168
  },
157
169
  ".." => {
158
170
  name: "..",
159
- description: "builds an inclusive range from the receiver to another value.",
160
- examples: ["1..3", ":a..:c", "Date.today..Date.tomorrow"]
171
+ description:
172
+ "builds an inclusive range from the receiver to another value.",
173
+ examples: %w[1..3 :a..:c Date.today..Date.tomorrow]
161
174
  },
162
175
  "inclusive_range" => {
163
176
  name: "inclusive_range",
164
- description: "builds an inclusive range from the receiver to another value.",
165
- examples: [
166
- "1.inclusive_range(3)",
167
- ":a.inclusive_range(:c)",
168
- "Date.today.inclusive_range(Date.tomorrow)"
177
+ description:
178
+ "builds an inclusive range from the receiver to another value.",
179
+ examples: %w[
180
+ 1.inclusive_range(3)
181
+ :a.inclusive_range(:c)
182
+ Date.today.inclusive_range(Date.tomorrow)
169
183
  ]
170
184
  },
171
185
  "..." => {
172
186
  name: "...",
173
- description: "builds an exclusive range from the receiver to another value.",
174
- examples: ["1...3", ":a...:c", "Date.today...Date.tomorrow"]
187
+ description:
188
+ "builds an exclusive range from the receiver to another value.",
189
+ examples: %w[1...3 :a...:c Date.today...Date.tomorrow]
175
190
  },
176
191
  "exclusive_range" => {
177
192
  name: "exclusive_range",
178
- description: "builds an exclusive range from the receiver to another value.",
179
- examples: [
180
- "1.exclusive_range(3)",
181
- ":a.exclusive_range(:c)",
182
- "Date.today.exclusive_range(Date.tomorrow)"
193
+ description:
194
+ "builds an exclusive range from the receiver to another value.",
195
+ examples: %w[
196
+ 1.exclusive_range(3)
197
+ :a.exclusive_range(:c)
198
+ Date.today.exclusive_range(Date.tomorrow)
183
199
  ]
184
200
  },
185
201
  "==" => {
@@ -199,7 +215,8 @@ class Code
199
215
  },
200
216
  "same_object?" => {
201
217
  name: "same_object?",
202
- description: "returns whether the value and argument are the same object.",
218
+ description:
219
+ "returns whether the value and argument are the same object.",
203
220
  examples: [
204
221
  "a = [] b = a a.same_object?(b)",
205
222
  "[].same_object?([])",
@@ -214,38 +231,42 @@ class Code
214
231
  "greater" => {
215
232
  name: "greater",
216
233
  description: "returns whether the value is greater than another value.",
217
- examples: [
218
- "2.greater(1)",
219
- ":b.greater(:a)",
220
- "Date.tomorrow.greater(Date.today)"
234
+ examples: %w[
235
+ 2.greater(1)
236
+ :b.greater(:a)
237
+ Date.tomorrow.greater(Date.today)
221
238
  ]
222
239
  },
223
240
  ">=" => {
224
241
  name: ">=",
225
- description: "returns whether the value is greater than or equal to another value.",
242
+ description:
243
+ "returns whether the value is greater than or equal to another value.",
226
244
  examples: ["2 >= 2", ":b >= :a", "Date.today >= Date.today"]
227
245
  },
228
246
  "greater_or_equal" => {
229
247
  name: "greater_or_equal",
230
- description: "returns whether the value is greater than or equal to another value.",
231
- examples: [
232
- "2.greater_or_equal(2)",
233
- ":b.greater_or_equal(:a)",
234
- "Date.today.greater_or_equal(Date.today)"
248
+ description:
249
+ "returns whether the value is greater than or equal to another value.",
250
+ examples: %w[
251
+ 2.greater_or_equal(2)
252
+ :b.greater_or_equal(:a)
253
+ Date.today.greater_or_equal(Date.today)
235
254
  ]
236
255
  },
237
256
  "<=>" => {
238
257
  name: "<=>",
239
- description: "compares the value with another value and returns -1, 0, or 1.",
258
+ description:
259
+ "compares the value with another value and returns -1, 0, or 1.",
240
260
  examples: ["1 <=> 2", ":a <=> :b", "Date.today <=> Date.tomorrow"]
241
261
  },
242
262
  "compare" => {
243
263
  name: "compare",
244
- description: "compares the value with another value and returns -1, 0, or 1.",
245
- examples: [
246
- "1.compare(2)",
247
- ":a.compare(:b)",
248
- "Date.today.compare(Date.tomorrow)"
264
+ description:
265
+ "compares the value with another value and returns -1, 0, or 1.",
266
+ examples: %w[
267
+ 1.compare(2)
268
+ :a.compare(:b)
269
+ Date.today.compare(Date.tomorrow)
249
270
  ]
250
271
  },
251
272
  "<" => {
@@ -256,20 +277,22 @@ class Code
256
277
  "less" => {
257
278
  name: "less",
258
279
  description: "returns whether the value is less than another value.",
259
- examples: ["1.less(2)", ":a.less(:b)", "Date.today.less(Date.tomorrow)"]
280
+ examples: %w[1.less(2) :a.less(:b) Date.today.less(Date.tomorrow)]
260
281
  },
261
282
  "<=" => {
262
283
  name: "<=",
263
- description: "returns whether the value is less than or equal to another value.",
284
+ description:
285
+ "returns whether the value is less than or equal to another value.",
264
286
  examples: ["1 <= 1", ":a <= :b", "Date.today <= Date.today"]
265
287
  },
266
288
  "less_or_equal" => {
267
289
  name: "less_or_equal",
268
- description: "returns whether the value is less than or equal to another value.",
269
- examples: [
270
- "1.less_or_equal(1)",
271
- ":a.less_or_equal(:b)",
272
- "Date.today.less_or_equal(Date.today)"
290
+ description:
291
+ "returns whether the value is less than or equal to another value.",
292
+ examples: %w[
293
+ 1.less_or_equal(1)
294
+ :a.less_or_equal(:b)
295
+ Date.today.less_or_equal(Date.today)
273
296
  ]
274
297
  },
275
298
  "===" => {
@@ -280,16 +303,22 @@ class Code
280
303
  "strict_equal" => {
281
304
  name: "strict_equal",
282
305
  description: "returns whether the value strictly equals another value.",
283
- examples: ["1.strict_equal(1)", ":a.strict_equal(:a)", "[1].strict_equal([1])"]
306
+ examples: [
307
+ "1.strict_equal(1)",
308
+ ":a.strict_equal(:a)",
309
+ "[1].strict_equal([1])"
310
+ ]
284
311
  },
285
312
  "!==" => {
286
313
  name: "!==",
287
- description: "returns whether the value does not strictly equal another value.",
314
+ description:
315
+ "returns whether the value does not strictly equal another value.",
288
316
  examples: ["1 !== 2", ":a !== :b", "[1] !== [2]"]
289
317
  },
290
318
  "strict_different" => {
291
319
  name: "strict_different",
292
- description: "returns whether the value does not strictly equal another value.",
320
+ description:
321
+ "returns whether the value does not strictly equal another value.",
293
322
  examples: [
294
323
  "1.strict_different(2)",
295
324
  ":a.strict_different(:b)",
@@ -299,32 +328,34 @@ class Code
299
328
  "falsy?" => {
300
329
  name: "falsy?",
301
330
  description: "returns whether the value is falsy.",
302
- examples: ["nothing.falsy?", "false.falsy?", "1.falsy?"]
331
+ examples: %w[nothing.falsy? false.falsy? 1.falsy?]
303
332
  },
304
333
  "truthy?" => {
305
334
  name: "truthy?",
306
335
  description: "returns whether the value is truthy.",
307
- examples: ["1.truthy?", "true.truthy?", "nothing.truthy?"]
336
+ examples: %w[1.truthy? true.truthy? nothing.truthy?]
308
337
  },
309
338
  "true?" => {
310
339
  name: "true?",
311
340
  description: "returns whether the value is true.",
312
- examples: ["true.true?", "false.true?", "1.true?"]
341
+ examples: %w[true.true? false.true? 1.true?]
313
342
  },
314
343
  "false?" => {
315
344
  name: "false?",
316
345
  description: "returns whether the value is false or nothing.",
317
- examples: ["false.false?", "nothing.false?", "true.false?"]
346
+ examples: %w[false.false? nothing.false? true.false?]
318
347
  },
319
348
  "||" => {
320
349
  name: "||",
321
- description: "returns the receiver when truthy, otherwise the other value.",
350
+ description:
351
+ "returns the receiver when truthy, otherwise the other value.",
322
352
  examples: ["nothing || 1", "false || 1", "2 || 1"]
323
353
  },
324
354
  "or" => {
325
355
  name: "or",
326
- description: "returns the receiver when truthy, otherwise the other value.",
327
- examples: ["nothing.or(1)", "false.or(1)", "2.or(1)"]
356
+ description:
357
+ "returns the receiver when truthy, otherwise the other value.",
358
+ examples: %w[nothing.or(1) false.or(1) 2.or(1)]
328
359
  },
329
360
  "to_boolean" => {
330
361
  name: "to_boolean",
@@ -353,12 +384,16 @@ class Code
353
384
  "to_dictionary" => {
354
385
  name: "to_dictionary",
355
386
  description: "converts the value to a dictionary.",
356
- examples: ["[].to_dictionary", "{}.to_dictionary", "[[:a, 1]].to_dictionary"]
387
+ examples: [
388
+ "[].to_dictionary",
389
+ "{}.to_dictionary",
390
+ "[[:a, 1]].to_dictionary"
391
+ ]
357
392
  },
358
393
  "to_duration" => {
359
394
  name: "to_duration",
360
395
  description: "converts the value to a duration.",
361
- examples: ["1.to_duration", "1.day.to_duration", "2.hours.to_duration"]
396
+ examples: %w[1.to_duration 1.day.to_duration 2.hours.to_duration]
362
397
  },
363
398
  "to_integer" => {
364
399
  name: "to_integer",
@@ -383,11 +418,12 @@ class Code
383
418
  "to_string" => {
384
419
  name: "to_string",
385
420
  description: "converts the value to a string.",
386
- examples: ["1.to_string", "true.to_string", ":a.to_string"]
421
+ examples: %w[1.to_string true.to_string :a.to_string]
387
422
  },
388
423
  "inspect" => {
389
424
  name: "inspect",
390
- description: "returns a string representation of the value for inspection.",
425
+ description:
426
+ "returns a string representation of the value for inspection.",
391
427
  examples: ["1.inspect", ":a.inspect", "[1].inspect"]
392
428
  },
393
429
  "to_time" => {
@@ -448,7 +484,8 @@ class Code
448
484
  },
449
485
  "tap" => {
450
486
  name: "tap",
451
- description: "calls a function with the receiver and returns the receiver.",
487
+ description:
488
+ "calls a function with the receiver and returns the receiver.",
452
489
  examples: [
453
490
  "1.tap((value) => { value })",
454
491
  ":a.tap((value) => { value.upcase })",
@@ -457,7 +494,8 @@ class Code
457
494
  },
458
495
  "then" => {
459
496
  name: "then",
460
- description: "calls a function with the receiver and returns the function result.",
497
+ description:
498
+ "calls a function with the receiver and returns the function result.",
461
499
  examples: [
462
500
  "1.then((value) => { value + 1 })",
463
501
  ":a.then((value) => { value.upcase })",
@@ -472,12 +510,12 @@ class Code
472
510
  "nothing?" => {
473
511
  name: "nothing?",
474
512
  description: "returns whether the value is nothing.",
475
- examples: ["nothing.nothing?", "1.nothing?", ":a.nothing?"]
513
+ examples: %w[nothing.nothing? 1.nothing? :a.nothing?]
476
514
  },
477
515
  "something?" => {
478
516
  name: "something?",
479
517
  description: "returns whether the value is not nothing.",
480
- examples: ["1.something?", ":a.something?", "nothing.something?"]
518
+ examples: %w[1.something? :a.something? nothing.something?]
481
519
  }
482
520
  }.freeze
483
521
  CLASS_FUNCTIONS = {
@@ -545,7 +583,9 @@ class Code
545
583
  end
546
584
 
547
585
  def self.documented_functions_for(klass, scope)
548
- sorted_dictionary(function_documentation_for(klass, scope).transform_keys(&:to_s))
586
+ sorted_dictionary(
587
+ function_documentation_for(klass, scope).transform_keys(&:to_s)
588
+ )
549
589
  end
550
590
 
551
591
  def self.documentation_for(klass)
@@ -558,8 +598,7 @@ class Code
558
598
 
559
599
  def self.function_documentation_for(klass, scope)
560
600
  documentation = function_documentation_registry_for(klass, scope)
561
- inherited_function_documentation_for(klass, scope)
562
- .merge(documentation)
601
+ inherited_function_documentation_for(klass, scope).merge(documentation)
563
602
  end
564
603
 
565
604
  def self.inherited_function_documentation_for(klass, scope)
data/lib/code/parser.rb CHANGED
@@ -32,37 +32,37 @@ class Code
32
32
  while
33
33
  ].freeze
34
34
 
35
- MULTI_CHAR_OPERATORS = [
36
- "&.",
37
- "&&",
38
- "&&=",
39
- "**",
40
- "*=",
41
- "+=",
42
- "-=",
43
- "..",
44
- "...",
45
- "/=",
46
- "::",
47
- "<<=",
48
- "<<",
49
- "<=>",
50
- "<=",
51
- "===",
52
- "==",
53
- "=~",
54
- ">=",
55
- ">>=",
56
- ">>",
57
- "||=",
58
- "||",
59
- "|=",
60
- "!==",
61
- "!=",
62
- "!~",
63
- "%=",
64
- "^=",
65
- "=>"
35
+ MULTI_CHAR_OPERATORS = %w[
36
+ &.
37
+ &&
38
+ &&=
39
+ **
40
+ *=
41
+ +=
42
+ -=
43
+ ..
44
+ ...
45
+ /=
46
+ ::
47
+ <<=
48
+ <<
49
+ <=>
50
+ <=
51
+ ===
52
+ ==
53
+ =~
54
+ >=
55
+ >>=
56
+ >>
57
+ ||=
58
+ ||
59
+ |=
60
+ !==
61
+ !=
62
+ !~
63
+ %=
64
+ ^=
65
+ =>
66
66
  ].sort_by(&:length).reverse.freeze
67
67
  CONTINUATION_KEYWORDS = %w[or and rescue].freeze
68
68
  POSTFIX_CONTINUATIONS = %w[. :: &.].freeze
@@ -1015,7 +1015,9 @@ class Code
1015
1015
  next
1016
1016
  elsif "([{".include?(char)
1017
1017
  depth += 1
1018
- raise_parse_error_at("source is too deeply nested", index) if depth > MAX_NESTING
1018
+ if depth > MAX_NESTING
1019
+ raise_parse_error_at("source is too deeply nested", index)
1020
+ end
1019
1021
  elsif ")]}".include?(char)
1020
1022
  depth -= 1 if depth.positive?
1021
1023
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié