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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/code +8 -5
- data/lib/code/concerns/shared.rb +102 -98
- data/lib/code/format.rb +23 -19
- data/lib/code/network.rb +23 -28
- data/lib/code/node/call.rb +9 -8
- data/lib/code/node/code.rb +1 -1
- data/lib/code/node/list.rb +10 -8
- data/lib/code/node/square_bracket.rb +4 -2
- data/lib/code/object/boolean.rb +13 -17
- data/lib/code/object/class.rb +32 -27
- data/lib/code/object/code.rb +2 -9
- data/lib/code/object/context.rb +4 -2
- data/lib/code/object/cryptography.rb +12 -6
- data/lib/code/object/date.rb +910 -449
- data/lib/code/object/decimal.rb +229 -856
- data/lib/code/object/dictionary.rb +113 -42
- data/lib/code/object/duration.rb +3 -7
- data/lib/code/object/function.rb +64 -40
- data/lib/code/object/global.rb +121 -208
- data/lib/code/object/html.rb +4 -2
- data/lib/code/object/http.rb +32 -26
- data/lib/code/object/ics.rb +2 -1
- data/lib/code/object/identifier_list.rb +16 -11
- data/lib/code/object/integer.rb +270 -942
- data/lib/code/object/json.rb +8 -3
- data/lib/code/object/list.rb +97 -109
- data/lib/code/object/nothing.rb +11 -11
- data/lib/code/object/number.rb +20 -10
- data/lib/code/object/parameter.rb +18 -9
- data/lib/code/object/range.rb +62 -108
- data/lib/code/object/smtp.rb +20 -12
- data/lib/code/object/string.rb +52 -28
- data/lib/code/object/super.rb +2 -1
- data/lib/code/object/time.rb +1146 -572
- data/lib/code/object/url.rb +4 -2
- data/lib/code/object.rb +119 -80
- data/lib/code/parser.rb +34 -32
- metadata +1 -1
|
@@ -5,7 +5,8 @@ class Code
|
|
|
5
5
|
class Parameter < Dictionary
|
|
6
6
|
CLASS_DOCUMENTATION = {
|
|
7
7
|
name: "Parameter",
|
|
8
|
-
description:
|
|
8
|
+
description:
|
|
9
|
+
"describes one function parameter with its name, kind flags, and default value.",
|
|
9
10
|
examples: [
|
|
10
11
|
"((name) => { name }).parameters.first",
|
|
11
12
|
"((name:) => { name }).parameters.first.keyword?",
|
|
@@ -24,7 +25,8 @@ class Code
|
|
|
24
25
|
},
|
|
25
26
|
"regular?" => {
|
|
26
27
|
name: "regular?",
|
|
27
|
-
description:
|
|
28
|
+
description:
|
|
29
|
+
"returns whether the parameter is not a keyword parameter.",
|
|
28
30
|
examples: [
|
|
29
31
|
"((name) => { name }).parameters.first.regular?",
|
|
30
32
|
"((name:) => { name }).parameters.first.regular?",
|
|
@@ -33,7 +35,8 @@ class Code
|
|
|
33
35
|
},
|
|
34
36
|
"keyword?" => {
|
|
35
37
|
name: "keyword?",
|
|
36
|
-
description:
|
|
38
|
+
description:
|
|
39
|
+
"returns whether the parameter is a named keyword parameter.",
|
|
37
40
|
examples: [
|
|
38
41
|
"((name:) => { name }).parameters.first.keyword?",
|
|
39
42
|
"((name) => { name }).parameters.first.keyword?",
|
|
@@ -42,7 +45,8 @@ class Code
|
|
|
42
45
|
},
|
|
43
46
|
"regular_splat?" => {
|
|
44
47
|
name: "regular_splat?",
|
|
45
|
-
description:
|
|
48
|
+
description:
|
|
49
|
+
"returns whether the parameter captures positional arguments with *.",
|
|
46
50
|
examples: [
|
|
47
51
|
"((...values) => { values }).parameters.first.regular_splat?",
|
|
48
52
|
"((*values) => { values }).parameters.first.regular_splat?",
|
|
@@ -51,7 +55,8 @@ class Code
|
|
|
51
55
|
},
|
|
52
56
|
"keyword_splat?" => {
|
|
53
57
|
name: "keyword_splat?",
|
|
54
|
-
description:
|
|
58
|
+
description:
|
|
59
|
+
"returns whether the parameter captures keyword arguments with **.",
|
|
55
60
|
examples: [
|
|
56
61
|
"((**options) => { options }).parameters.first.keyword_splat?",
|
|
57
62
|
"((name:) => { name }).parameters.first.keyword_splat?",
|
|
@@ -60,7 +65,8 @@ class Code
|
|
|
60
65
|
},
|
|
61
66
|
"block?" => {
|
|
62
67
|
name: "block?",
|
|
63
|
-
description:
|
|
68
|
+
description:
|
|
69
|
+
"returns whether the parameter captures one function argument with &.",
|
|
64
70
|
examples: [
|
|
65
71
|
"((&block) => { block }).parameters.first.block?",
|
|
66
72
|
"((name) => { name }).parameters.first.block?",
|
|
@@ -69,7 +75,8 @@ class Code
|
|
|
69
75
|
},
|
|
70
76
|
"blocks?" => {
|
|
71
77
|
name: "blocks?",
|
|
72
|
-
description:
|
|
78
|
+
description:
|
|
79
|
+
"returns whether the parameter captures remaining function arguments with &&.",
|
|
73
80
|
examples: [
|
|
74
81
|
"((&&blocks) => { blocks }).parameters.first.blocks?",
|
|
75
82
|
"((&block) => { block }).parameters.first.blocks?",
|
|
@@ -78,7 +85,8 @@ class Code
|
|
|
78
85
|
},
|
|
79
86
|
"spread?" => {
|
|
80
87
|
name: "spread?",
|
|
81
|
-
description:
|
|
88
|
+
description:
|
|
89
|
+
"returns whether the parameter captures every provided argument with spread syntax.",
|
|
82
90
|
examples: [
|
|
83
91
|
"((...values) => { values }).parameters.first.spread?",
|
|
84
92
|
"((name) => { name }).parameters.first.spread?",
|
|
@@ -105,7 +113,8 @@ class Code
|
|
|
105
113
|
},
|
|
106
114
|
"default" => {
|
|
107
115
|
name: "default",
|
|
108
|
-
description:
|
|
116
|
+
description:
|
|
117
|
+
"returns the default value for the parameter, or nothing when none is set.",
|
|
109
118
|
examples: [
|
|
110
119
|
"((name = :a) => { name }).parameters.first.default",
|
|
111
120
|
"((name) => { name }).parameters.first.default",
|
data/lib/code/object/range.rb
CHANGED
|
@@ -5,17 +5,15 @@ class Code
|
|
|
5
5
|
class Range < Object
|
|
6
6
|
CLASS_DOCUMENTATION = {
|
|
7
7
|
name: "Range",
|
|
8
|
-
description:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"1...3",
|
|
12
|
-
"(1..3).to_list"
|
|
13
|
-
]
|
|
8
|
+
description:
|
|
9
|
+
"represents inclusive or exclusive sequences between comparable bounds.",
|
|
10
|
+
examples: %w[1..3 1...3 (1..3).to_list]
|
|
14
11
|
}.freeze
|
|
15
12
|
INSTANCE_FUNCTIONS = {
|
|
16
13
|
"all?" => {
|
|
17
14
|
name: "all?",
|
|
18
|
-
description:
|
|
15
|
+
description:
|
|
16
|
+
"returns whether every item in the range matches a function.",
|
|
19
17
|
examples: [
|
|
20
18
|
"(1..3).all?((x) => { x > 0 })",
|
|
21
19
|
"(1..3).all?((x) => { x < 4 })",
|
|
@@ -24,7 +22,8 @@ class Code
|
|
|
24
22
|
},
|
|
25
23
|
"any?" => {
|
|
26
24
|
name: "any?",
|
|
27
|
-
description:
|
|
25
|
+
description:
|
|
26
|
+
"returns whether any item in the range matches a function.",
|
|
28
27
|
examples: [
|
|
29
28
|
"(1..3).any?((x) => { x == 2 })",
|
|
30
29
|
"(1..3).any?((x) => { x == 1 })",
|
|
@@ -33,7 +32,8 @@ class Code
|
|
|
33
32
|
},
|
|
34
33
|
"none?" => {
|
|
35
34
|
name: "none?",
|
|
36
|
-
description:
|
|
35
|
+
description:
|
|
36
|
+
"returns whether no items in the range match a function.",
|
|
37
37
|
examples: [
|
|
38
38
|
"(1..3).none?((x) => { x > 3 })",
|
|
39
39
|
"(1..3).none?((x) => { x == 2 })",
|
|
@@ -42,7 +42,8 @@ class Code
|
|
|
42
42
|
},
|
|
43
43
|
"each" => {
|
|
44
44
|
name: "each",
|
|
45
|
-
description:
|
|
45
|
+
description:
|
|
46
|
+
"calls a function for each item in the range and returns the range.",
|
|
46
47
|
examples: [
|
|
47
48
|
"(1..3).each((x) => { x })",
|
|
48
49
|
"(:a..:c).each((x) => { x })",
|
|
@@ -51,7 +52,8 @@ class Code
|
|
|
51
52
|
},
|
|
52
53
|
"reverse_each" => {
|
|
53
54
|
name: "reverse_each",
|
|
54
|
-
description:
|
|
55
|
+
description:
|
|
56
|
+
"calls a function for each item in the range in reverse order.",
|
|
55
57
|
examples: [
|
|
56
58
|
"(1..3).reverse_each((x) => { x })",
|
|
57
59
|
"(:a..:c).reverse_each((x) => { x })",
|
|
@@ -61,123 +63,88 @@ class Code
|
|
|
61
63
|
"include?" => {
|
|
62
64
|
name: "include?",
|
|
63
65
|
description: "returns whether the range includes a value.",
|
|
64
|
-
examples: [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
examples: %w[
|
|
67
|
+
(1..3).include?(2)
|
|
68
|
+
(1..3).include?(4)
|
|
69
|
+
(:a..:c).include?(:b)
|
|
68
70
|
]
|
|
69
71
|
},
|
|
70
72
|
"member?" => {
|
|
71
73
|
name: "member?",
|
|
72
74
|
description: "returns whether the range includes a value.",
|
|
73
|
-
examples: [
|
|
74
|
-
"(1..3).member?(2)",
|
|
75
|
-
"(1..3).member?(4)",
|
|
76
|
-
"(:a..:c).member?(:b)"
|
|
77
|
-
]
|
|
75
|
+
examples: %w[(1..3).member?(2) (1..3).member?(4) (:a..:c).member?(:b)]
|
|
78
76
|
},
|
|
79
77
|
"cover?" => {
|
|
80
78
|
name: "cover?",
|
|
81
79
|
description: "returns whether a value is between the range bounds.",
|
|
82
|
-
examples: [
|
|
83
|
-
"(1..3).cover?(2)",
|
|
84
|
-
"(1..3).cover?(4)",
|
|
85
|
-
"(:a..:c).cover?(:b)"
|
|
86
|
-
]
|
|
80
|
+
examples: %w[(1..3).cover?(2) (1..3).cover?(4) (:a..:c).cover?(:b)]
|
|
87
81
|
},
|
|
88
82
|
"overlap?" => {
|
|
89
83
|
name: "overlap?",
|
|
90
84
|
description: "returns whether the range overlaps another range.",
|
|
91
|
-
examples: [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
examples: %w[
|
|
86
|
+
(1..3).overlap?(2..4)
|
|
87
|
+
(1..3).overlap?(4..6)
|
|
88
|
+
(:a..:c).overlap?(:b..:d)
|
|
95
89
|
]
|
|
96
90
|
},
|
|
97
91
|
"empty?" => {
|
|
98
92
|
name: "empty?",
|
|
99
93
|
description: "returns whether the range is empty.",
|
|
100
|
-
examples: [
|
|
101
|
-
"(1..3).empty?",
|
|
102
|
-
"(1...1).empty?",
|
|
103
|
-
"(:a..:c).empty?"
|
|
104
|
-
]
|
|
94
|
+
examples: %w[(1..3).empty? (1...1).empty? (:a..:c).empty?]
|
|
105
95
|
},
|
|
106
96
|
"begin" => {
|
|
107
97
|
name: "begin",
|
|
108
98
|
description: "returns the starting bound of the range.",
|
|
109
|
-
examples: [
|
|
110
|
-
"(1..3).begin",
|
|
111
|
-
"(:a..:c).begin",
|
|
112
|
-
"(1...3).begin"
|
|
113
|
-
]
|
|
99
|
+
examples: %w[(1..3).begin (:a..:c).begin (1...3).begin]
|
|
114
100
|
},
|
|
115
101
|
"end" => {
|
|
116
102
|
name: "end",
|
|
117
103
|
description: "returns the ending bound of the range.",
|
|
118
|
-
examples: [
|
|
119
|
-
"(1..3).end",
|
|
120
|
-
"(:a..:c).end",
|
|
121
|
-
"(1...3).end"
|
|
122
|
-
]
|
|
104
|
+
examples: %w[(1..3).end (:a..:c).end (1...3).end]
|
|
123
105
|
},
|
|
124
106
|
"exclude_end?" => {
|
|
125
107
|
name: "exclude_end?",
|
|
126
108
|
description: "returns whether the range excludes its ending bound.",
|
|
127
|
-
examples: [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
109
|
+
examples: %w[
|
|
110
|
+
(1..3).exclude_end?
|
|
111
|
+
(1...3).exclude_end?
|
|
112
|
+
(:a...:c).exclude_end?
|
|
131
113
|
]
|
|
132
114
|
},
|
|
133
115
|
"first" => {
|
|
134
116
|
name: "first",
|
|
135
117
|
description: "returns the first item in the range.",
|
|
136
|
-
examples: [
|
|
137
|
-
"(1..3).first",
|
|
138
|
-
"(2..4).first",
|
|
139
|
-
"(:a..:c).first"
|
|
140
|
-
]
|
|
118
|
+
examples: %w[(1..3).first (2..4).first (:a..:c).first]
|
|
141
119
|
},
|
|
142
120
|
"last" => {
|
|
143
121
|
name: "last",
|
|
144
122
|
description: "returns the last item in the range.",
|
|
145
|
-
examples: [
|
|
146
|
-
"(1..3).last",
|
|
147
|
-
"(2..4).last",
|
|
148
|
-
"(:a..:c).last"
|
|
149
|
-
]
|
|
123
|
+
examples: %w[(1..3).last (2..4).last (:a..:c).last]
|
|
150
124
|
},
|
|
151
125
|
"minimum" => {
|
|
152
126
|
name: "minimum",
|
|
153
127
|
description: "returns the minimum item in the range.",
|
|
154
|
-
examples: [
|
|
155
|
-
"(1..3).minimum",
|
|
156
|
-
"(:a..:c).minimum",
|
|
157
|
-
"(3..1).minimum"
|
|
158
|
-
]
|
|
128
|
+
examples: %w[(1..3).minimum (:a..:c).minimum (3..1).minimum]
|
|
159
129
|
},
|
|
160
130
|
"maximum" => {
|
|
161
131
|
name: "maximum",
|
|
162
132
|
description: "returns the maximum item in the range.",
|
|
163
|
-
examples: [
|
|
164
|
-
"(1..3).maximum",
|
|
165
|
-
"(:a..:c).maximum",
|
|
166
|
-
"(3..1).maximum"
|
|
167
|
-
]
|
|
133
|
+
examples: %w[(1..3).maximum (:a..:c).maximum (3..1).maximum]
|
|
168
134
|
},
|
|
169
135
|
"minimum_maximum" => {
|
|
170
136
|
name: "minimum_maximum",
|
|
171
137
|
description: "returns the minimum and maximum items as a list.",
|
|
172
|
-
examples: [
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
138
|
+
examples: %w[
|
|
139
|
+
(1..3).minimum_maximum
|
|
140
|
+
(:a..:c).minimum_maximum
|
|
141
|
+
(3..1).minimum_maximum
|
|
176
142
|
]
|
|
177
143
|
},
|
|
178
144
|
"map" => {
|
|
179
145
|
name: "map",
|
|
180
|
-
description:
|
|
146
|
+
description:
|
|
147
|
+
"returns a list with each item transformed by a function.",
|
|
181
148
|
examples: [
|
|
182
149
|
"(1..3).map((x) => { x + 1 })",
|
|
183
150
|
"(1..3).map((x) => { x.to_string })",
|
|
@@ -214,11 +181,7 @@ class Code
|
|
|
214
181
|
"step" => {
|
|
215
182
|
name: "step",
|
|
216
183
|
description: "returns a list of items separated by a step size.",
|
|
217
|
-
examples: [
|
|
218
|
-
"(1..5).step(2)",
|
|
219
|
-
"(1..5).step(1)",
|
|
220
|
-
"(1...5).step(2)"
|
|
221
|
-
]
|
|
184
|
+
examples: %w[(1..5).step(2) (1..5).step(1) (1...5).step(2)]
|
|
222
185
|
},
|
|
223
186
|
"binary_search" => {
|
|
224
187
|
name: "binary_search",
|
|
@@ -232,24 +195,17 @@ class Code
|
|
|
232
195
|
"sample" => {
|
|
233
196
|
name: "sample",
|
|
234
197
|
description: "returns a random item from the range.",
|
|
235
|
-
examples: [
|
|
236
|
-
"(1..3).sample",
|
|
237
|
-
"(2..4).sample",
|
|
238
|
-
"(:a..:c).sample"
|
|
239
|
-
]
|
|
198
|
+
examples: %w[(1..3).sample (2..4).sample (:a..:c).sample]
|
|
240
199
|
},
|
|
241
200
|
"size" => {
|
|
242
201
|
name: "size",
|
|
243
202
|
description: "returns the number of items in the range.",
|
|
244
|
-
examples: [
|
|
245
|
-
"(1..3).size",
|
|
246
|
-
"(1...3).size",
|
|
247
|
-
"(:a..:c).size"
|
|
248
|
-
]
|
|
203
|
+
examples: %w[(1..3).size (1...3).size (:a..:c).size]
|
|
249
204
|
},
|
|
250
205
|
"count" => {
|
|
251
206
|
name: "count",
|
|
252
|
-
description:
|
|
207
|
+
description:
|
|
208
|
+
"returns the number of items, optionally matched by a function.",
|
|
253
209
|
examples: [
|
|
254
210
|
"(1..3).count",
|
|
255
211
|
"(1...3).count",
|
|
@@ -259,28 +215,20 @@ class Code
|
|
|
259
215
|
"to_list" => {
|
|
260
216
|
name: "to_list",
|
|
261
217
|
description: "returns the range items as a list.",
|
|
262
|
-
examples: [
|
|
263
|
-
"(1..3).to_list",
|
|
264
|
-
"(1...3).to_list",
|
|
265
|
-
"(:a..:c).to_list"
|
|
266
|
-
]
|
|
218
|
+
examples: %w[(1..3).to_list (1...3).to_list (:a..:c).to_list]
|
|
267
219
|
},
|
|
268
220
|
"entries" => {
|
|
269
221
|
name: "entries",
|
|
270
222
|
description: "returns the range items as a list.",
|
|
271
|
-
examples: [
|
|
272
|
-
"(1..3).entries",
|
|
273
|
-
"(1...3).entries",
|
|
274
|
-
"(:a..:c).entries"
|
|
275
|
-
]
|
|
223
|
+
examples: %w[(1..3).entries (1...3).entries (:a..:c).entries]
|
|
276
224
|
},
|
|
277
225
|
"to_dictionary" => {
|
|
278
226
|
name: "to_dictionary",
|
|
279
227
|
description: "returns a dictionary built from indexed range items.",
|
|
280
|
-
examples: [
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
228
|
+
examples: %w[
|
|
229
|
+
(1..3).to_dictionary
|
|
230
|
+
(1...3).to_dictionary
|
|
231
|
+
(:a..:c).to_dictionary
|
|
284
232
|
]
|
|
285
233
|
}
|
|
286
234
|
}.freeze
|
|
@@ -707,9 +655,17 @@ class Code
|
|
|
707
655
|
loop do
|
|
708
656
|
comparison =
|
|
709
657
|
if step_is_positive
|
|
710
|
-
exclude_end?
|
|
658
|
+
if exclude_end?
|
|
659
|
+
code_element.code_less(code_right)
|
|
660
|
+
else
|
|
661
|
+
code_element.code_less_or_equal(code_right)
|
|
662
|
+
end
|
|
711
663
|
else
|
|
712
|
-
exclude_end?
|
|
664
|
+
if exclude_end?
|
|
665
|
+
code_element.code_greater(code_right)
|
|
666
|
+
else
|
|
667
|
+
code_element.code_greater_or_equal(code_right)
|
|
668
|
+
end
|
|
713
669
|
end
|
|
714
670
|
|
|
715
671
|
break unless comparison.truthy?
|
|
@@ -755,9 +711,7 @@ class Code
|
|
|
755
711
|
def code_count(argument = nil, **globals)
|
|
756
712
|
code_argument = argument.to_code
|
|
757
713
|
|
|
758
|
-
if code_argument.nothing?
|
|
759
|
-
return Integer.new(raw.to_a.size)
|
|
760
|
-
end
|
|
714
|
+
return Integer.new(raw.to_a.size) if code_argument.nothing?
|
|
761
715
|
|
|
762
716
|
index = 0
|
|
763
717
|
Integer.new(
|
data/lib/code/object/smtp.rb
CHANGED
|
@@ -6,20 +6,16 @@ class Code
|
|
|
6
6
|
CLASS_DOCUMENTATION = {
|
|
7
7
|
name: "Smtp",
|
|
8
8
|
description: "stores smtp settings and sends email messages.",
|
|
9
|
-
examples: [
|
|
10
|
-
"Smtp",
|
|
11
|
-
"Smtp.new",
|
|
12
|
-
"Smtp.new.functions.keys.include?(:send)"
|
|
13
|
-
]
|
|
9
|
+
examples: %w[Smtp Smtp.new Smtp.new.functions.keys.include?(:send)]
|
|
14
10
|
}.freeze
|
|
15
11
|
INSTANCE_FUNCTIONS = {
|
|
16
12
|
"send" => {
|
|
17
13
|
name: "send",
|
|
18
14
|
description: "sends an email using the receiver's smtp settings.",
|
|
19
|
-
examples: [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
examples: %w[
|
|
16
|
+
Smtp.new.respond_to?(:send)
|
|
17
|
+
Smtp.new.functions.keys.include?(:send)
|
|
18
|
+
Smtp.new.instance_functions.keys.include?(:send)
|
|
23
19
|
]
|
|
24
20
|
}
|
|
25
21
|
}.freeze
|
|
@@ -127,14 +123,23 @@ class Code
|
|
|
127
123
|
private
|
|
128
124
|
|
|
129
125
|
def validate_delivery_target!(address, port)
|
|
130
|
-
resolved_ip =
|
|
126
|
+
resolved_ip =
|
|
127
|
+
::Code::Network.validate_public_host!(address, service: "smtp").first
|
|
131
128
|
|
|
132
129
|
return resolved_ip if ALLOWED_PORTS.include?(port)
|
|
133
130
|
|
|
134
131
|
raise Error, "smtp: unsupported port"
|
|
135
132
|
end
|
|
136
133
|
|
|
137
|
-
def deliver_mail(
|
|
134
|
+
def deliver_mail(
|
|
135
|
+
mail,
|
|
136
|
+
address:,
|
|
137
|
+
resolved_ip:,
|
|
138
|
+
port:,
|
|
139
|
+
user_name:,
|
|
140
|
+
password:,
|
|
141
|
+
authentication:
|
|
142
|
+
)
|
|
138
143
|
envelope = Mail::SmtpEnvelope.new(mail)
|
|
139
144
|
smtp =
|
|
140
145
|
Net::SMTP.new(
|
|
@@ -161,7 +166,10 @@ class Code
|
|
|
161
166
|
end
|
|
162
167
|
rescue Timeout::Error
|
|
163
168
|
raise Error, "smtp timeout"
|
|
164
|
-
rescue OpenSSL::SSL::SSLError,
|
|
169
|
+
rescue OpenSSL::SSL::SSLError,
|
|
170
|
+
IOError,
|
|
171
|
+
SystemCallError,
|
|
172
|
+
SocketError,
|
|
165
173
|
Net::SMTPError
|
|
166
174
|
raise Error, "smtp error"
|
|
167
175
|
end
|
data/lib/code/object/string.rb
CHANGED
|
@@ -5,12 +5,9 @@ class Code
|
|
|
5
5
|
class String < Object
|
|
6
6
|
CLASS_DOCUMENTATION = {
|
|
7
7
|
name: "String",
|
|
8
|
-
description:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
":hello.upcase",
|
|
12
|
-
"\"a,b\".split(\",\")"
|
|
13
|
-
]
|
|
8
|
+
description:
|
|
9
|
+
"represents text and provides parsing, search, and transformation operations.",
|
|
10
|
+
examples: ["\"hello\"", ":hello.upcase", "\"a,b\".split(\",\")"]
|
|
14
11
|
}.freeze
|
|
15
12
|
INSTANCE_FUNCTIONS = {
|
|
16
13
|
"&" => {
|
|
@@ -40,7 +37,11 @@ class Code
|
|
|
40
37
|
"downcase" => {
|
|
41
38
|
name: "downcase",
|
|
42
39
|
description: "returns the string converted to lowercase.",
|
|
43
|
-
examples: [
|
|
40
|
+
examples: [
|
|
41
|
+
"\"HELLO\".downcase",
|
|
42
|
+
"\"Code\".downcase",
|
|
43
|
+
"\"A1\".downcase"
|
|
44
|
+
]
|
|
44
45
|
},
|
|
45
46
|
"lower_case" => {
|
|
46
47
|
name: "lower_case",
|
|
@@ -122,7 +123,8 @@ class Code
|
|
|
122
123
|
},
|
|
123
124
|
"capitalize" => {
|
|
124
125
|
name: "capitalize",
|
|
125
|
-
description:
|
|
126
|
+
description:
|
|
127
|
+
"returns the string with its first character capitalized.",
|
|
126
128
|
examples: [
|
|
127
129
|
"\"hello\".capitalize",
|
|
128
130
|
"\"code\".capitalize",
|
|
@@ -132,7 +134,11 @@ class Code
|
|
|
132
134
|
"characters" => {
|
|
133
135
|
name: "characters",
|
|
134
136
|
description: "returns the string characters as a list.",
|
|
135
|
-
examples: [
|
|
137
|
+
examples: [
|
|
138
|
+
"\"abc\".characters",
|
|
139
|
+
"\"hi\".characters",
|
|
140
|
+
"\"\".characters"
|
|
141
|
+
]
|
|
136
142
|
},
|
|
137
143
|
"bytes" => {
|
|
138
144
|
name: "bytes",
|
|
@@ -156,7 +162,11 @@ class Code
|
|
|
156
162
|
"codepoints" => {
|
|
157
163
|
name: "codepoints",
|
|
158
164
|
description: "returns the string codepoints as a list.",
|
|
159
|
-
examples: [
|
|
165
|
+
examples: [
|
|
166
|
+
"\"abc\".codepoints",
|
|
167
|
+
"\"A\".codepoints",
|
|
168
|
+
"\"\".codepoints"
|
|
169
|
+
]
|
|
160
170
|
},
|
|
161
171
|
"character_code_at" => {
|
|
162
172
|
name: "character_code_at",
|
|
@@ -174,7 +184,8 @@ class Code
|
|
|
174
184
|
},
|
|
175
185
|
"chomp" => {
|
|
176
186
|
name: "chomp",
|
|
177
|
-
description:
|
|
187
|
+
description:
|
|
188
|
+
"returns the string with a trailing record separator removed.",
|
|
178
189
|
examples: ["\"a\\n\".chomp", "\"a\".chomp", "\"a\\r\\n\".chomp"]
|
|
179
190
|
},
|
|
180
191
|
"chop" => {
|
|
@@ -295,7 +306,8 @@ class Code
|
|
|
295
306
|
},
|
|
296
307
|
"parameterize" => {
|
|
297
308
|
name: "parameterize",
|
|
298
|
-
description:
|
|
309
|
+
description:
|
|
310
|
+
"returns the string parameterized for identifiers or urls.",
|
|
299
311
|
examples: [
|
|
300
312
|
"\"Hello world\".parameterize",
|
|
301
313
|
"\"a b c\".parameterize",
|
|
@@ -304,7 +316,8 @@ class Code
|
|
|
304
316
|
},
|
|
305
317
|
"squish" => {
|
|
306
318
|
name: "squish",
|
|
307
|
-
description:
|
|
319
|
+
description:
|
|
320
|
+
"returns the string with surrounding and repeated whitespace collapsed.",
|
|
308
321
|
examples: [
|
|
309
322
|
"\" hello world \".squish",
|
|
310
323
|
"\"a\\n b\".squish",
|
|
@@ -377,7 +390,11 @@ class Code
|
|
|
377
390
|
"swapcase" => {
|
|
378
391
|
name: "swapcase",
|
|
379
392
|
description: "returns the string with letter case swapped.",
|
|
380
|
-
examples: [
|
|
393
|
+
examples: [
|
|
394
|
+
"\"AbC\".swapcase",
|
|
395
|
+
"\"hello\".swapcase",
|
|
396
|
+
"\"ABC\".swapcase"
|
|
397
|
+
]
|
|
381
398
|
},
|
|
382
399
|
"titleize" => {
|
|
383
400
|
name: "titleize",
|
|
@@ -414,13 +431,18 @@ class Code
|
|
|
414
431
|
},
|
|
415
432
|
"strip" => {
|
|
416
433
|
name: "strip",
|
|
417
|
-
description:
|
|
434
|
+
description:
|
|
435
|
+
"returns the string with surrounding whitespace removed.",
|
|
418
436
|
examples: ["\" a \".strip", "\"\\na\".strip", "\"a\".strip"]
|
|
419
437
|
},
|
|
420
438
|
"left_strip" => {
|
|
421
439
|
name: "left_strip",
|
|
422
440
|
description: "returns the string with leading whitespace removed.",
|
|
423
|
-
examples: [
|
|
441
|
+
examples: [
|
|
442
|
+
"\" a\".left_strip",
|
|
443
|
+
"\"\\na\".left_strip",
|
|
444
|
+
"\"a\".left_strip"
|
|
445
|
+
]
|
|
424
446
|
},
|
|
425
447
|
"right_strip" => {
|
|
426
448
|
name: "right_strip",
|
|
@@ -434,7 +456,11 @@ class Code
|
|
|
434
456
|
"slice" => {
|
|
435
457
|
name: "slice",
|
|
436
458
|
description: "returns a slice from the string.",
|
|
437
|
-
examples: [
|
|
459
|
+
examples: [
|
|
460
|
+
"\"abc\".slice(0)",
|
|
461
|
+
"\"abc\".slice(0, 2)",
|
|
462
|
+
"\"abc\".slice(1)"
|
|
463
|
+
]
|
|
438
464
|
},
|
|
439
465
|
"left_justify" => {
|
|
440
466
|
name: "left_justify",
|
|
@@ -507,11 +533,7 @@ class Code
|
|
|
507
533
|
"words" => {
|
|
508
534
|
name: "words",
|
|
509
535
|
description: "returns the words in the string as a list.",
|
|
510
|
-
examples: [
|
|
511
|
-
"\"hello world\".words",
|
|
512
|
-
"\"one two\".words",
|
|
513
|
-
"\"\".words"
|
|
514
|
-
]
|
|
536
|
+
examples: ["\"hello world\".words", "\"one two\".words", "\"\".words"]
|
|
515
537
|
}
|
|
516
538
|
}.freeze
|
|
517
539
|
|
|
@@ -932,12 +954,13 @@ class Code
|
|
|
932
954
|
[
|
|
933
955
|
{
|
|
934
956
|
left_operation: {
|
|
935
|
-
first: {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
operator: ".",
|
|
939
|
-
statement: { call: { name: raw } }
|
|
957
|
+
first: {
|
|
958
|
+
call: {
|
|
959
|
+
name: "_"
|
|
940
960
|
}
|
|
961
|
+
},
|
|
962
|
+
others: [
|
|
963
|
+
{ operator: ".", statement: { call: { name: raw } } }
|
|
941
964
|
]
|
|
942
965
|
}
|
|
943
966
|
}
|
|
@@ -1095,7 +1118,8 @@ class Code
|
|
|
1095
1118
|
finish_index = code_finish.nothing? ? raw.length : code_finish.raw
|
|
1096
1119
|
start_index = 0 if start_index.negative?
|
|
1097
1120
|
finish_index = 0 if finish_index.negative?
|
|
1098
|
-
start_index, finish_index = finish_index, start_index if start_index >
|
|
1121
|
+
start_index, finish_index = finish_index, start_index if start_index >
|
|
1122
|
+
finish_index
|
|
1099
1123
|
|
|
1100
1124
|
String.new(raw[start_index...finish_index].to_s)
|
|
1101
1125
|
end
|
data/lib/code/object/super.rb
CHANGED
|
@@ -5,7 +5,8 @@ class Code
|
|
|
5
5
|
class Super < Function
|
|
6
6
|
CLASS_DOCUMENTATION = {
|
|
7
7
|
name: "Super",
|
|
8
|
-
description:
|
|
8
|
+
description:
|
|
9
|
+
"calls the captured parent function available inside an extended function.",
|
|
9
10
|
examples: [
|
|
10
11
|
"Base = () => { self.name = :base self } Child = Base.extend(() => { super() }) Child().name",
|
|
11
12
|
"Base = (name) => { self.name = name self } Child = Base.extend((...) => { super(...) }) Child(:ada).name",
|