code-ruby 3.1.2 → 4.0.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/VERSION +1 -1
- data/bin/code +97 -20
- data/lib/code/concerns/shared.rb +331 -15
- data/lib/code/format.rb +15 -1
- data/lib/code/network.rb +87 -0
- data/lib/code/node/call.rb +79 -2
- data/lib/code/node/call_argument.rb +14 -0
- data/lib/code/node/code.rb +5 -4
- data/lib/code/node/function_parameter.rb +7 -4
- data/lib/code/node/list.rb +29 -1
- data/lib/code/object/base_64.rb +132 -6
- data/lib/code/object/boolean.rb +60 -0
- data/lib/code/object/class.rb +138 -2
- data/lib/code/object/code.rb +111 -3
- data/lib/code/object/context.rb +57 -1
- data/lib/code/object/cryptography.rb +63 -0
- data/lib/code/object/date.rb +13339 -462
- data/lib/code/object/decimal.rb +1725 -0
- data/lib/code/object/dictionary.rb +1790 -11
- data/lib/code/object/duration.rb +28 -0
- data/lib/code/object/function.rb +261 -23
- data/lib/code/object/global.rb +534 -1
- data/lib/code/object/html.rb +179 -7
- data/lib/code/object/http.rb +244 -14
- data/lib/code/object/ics.rb +75 -13
- data/lib/code/object/identifier_list.rb +17 -2
- data/lib/code/object/integer.rb +1937 -2
- data/lib/code/object/json.rb +75 -1
- data/lib/code/object/list.rb +3383 -10
- data/lib/code/object/nothing.rb +53 -0
- data/lib/code/object/number.rb +110 -0
- data/lib/code/object/parameter.rb +140 -0
- data/lib/code/object/range.rb +576 -14
- data/lib/code/object/smtp.rb +95 -12
- data/lib/code/object/string.rb +944 -3
- data/lib/code/object/super.rb +10 -1
- data/lib/code/object/time.rb +13358 -498
- data/lib/code/object/url.rb +65 -0
- data/lib/code/object.rb +543 -0
- data/lib/code/parser.rb +161 -24
- data/lib/code-ruby.rb +3 -0
- data/lib/code.rb +30 -3
- metadata +135 -84
- data/.github/dependabot.yml +0 -15
- data/.github/workflows/ci.yml +0 -38
- data/.gitignore +0 -30
- data/.node-version +0 -1
- data/.npm-version +0 -1
- data/.prettierignore +0 -2
- data/.rspec +0 -1
- data/.rubocop.yml +0 -140
- data/.ruby-version +0 -1
- data/.tool-versions +0 -3
- data/AGENTS.md +0 -43
- data/Gemfile +0 -22
- data/Gemfile.lock +0 -292
- data/Rakefile +0 -5
- data/bin/bundle +0 -123
- data/bin/bundle-audit +0 -31
- data/bin/bundler-audit +0 -31
- data/bin/dorian +0 -31
- data/bin/rspec +0 -31
- data/bin/rubocop +0 -31
- data/bin/test +0 -5
- data/code-ruby.gemspec +0 -34
- data/docs/precedence.txt +0 -36
- data/package-lock.json +0 -14
- data/package.json +0 -7
- data/spec/bin/code_spec.rb +0 -48
- data/spec/code/format_spec.rb +0 -153
- data/spec/code/node/call_spec.rb +0 -11
- data/spec/code/object/boolean_spec.rb +0 -18
- data/spec/code/object/cryptography_spec.rb +0 -25
- data/spec/code/object/decimal_spec.rb +0 -50
- data/spec/code/object/dictionary_spec.rb +0 -98
- data/spec/code/object/function_spec.rb +0 -268
- data/spec/code/object/http_spec.rb +0 -33
- data/spec/code/object/ics_spec.rb +0 -50
- data/spec/code/object/integer_spec.rb +0 -42
- data/spec/code/object/list_spec.rb +0 -22
- data/spec/code/object/nothing_spec.rb +0 -14
- data/spec/code/object/range_spec.rb +0 -23
- data/spec/code/object/string_spec.rb +0 -26
- data/spec/code/parser/boolean_spec.rb +0 -11
- data/spec/code/parser/chained_call_spec.rb +0 -16
- data/spec/code/parser/dictionary_spec.rb +0 -18
- data/spec/code/parser/function_spec.rb +0 -16
- data/spec/code/parser/group_spec.rb +0 -11
- data/spec/code/parser/if_modifier_spec.rb +0 -18
- data/spec/code/parser/list_spec.rb +0 -17
- data/spec/code/parser/number_spec.rb +0 -11
- data/spec/code/parser/string_spec.rb +0 -20
- data/spec/code/parser_spec.rb +0 -52
- data/spec/code/type_spec.rb +0 -21
- data/spec/code_spec.rb +0 -717
- data/spec/spec_helper.rb +0 -21
- data/spec/zeitwerk/loader_spec.rb +0 -7
data/lib/code/object/nothing.rb
CHANGED
|
@@ -3,10 +3,59 @@
|
|
|
3
3
|
class Code
|
|
4
4
|
class Object
|
|
5
5
|
class Nothing < Object
|
|
6
|
+
CLASS_DOCUMENTATION = {
|
|
7
|
+
name: "Nothing",
|
|
8
|
+
description: "represents no value.",
|
|
9
|
+
examples: [
|
|
10
|
+
"nothing",
|
|
11
|
+
"Nothing.new",
|
|
12
|
+
"Nothing.new(1)"
|
|
13
|
+
]
|
|
14
|
+
}.freeze
|
|
15
|
+
INSTANCE_FUNCTIONS = {
|
|
16
|
+
"empty?" => {
|
|
17
|
+
name: "empty?",
|
|
18
|
+
description: "returns true because nothing has no contents.",
|
|
19
|
+
examples: ["nothing.empty?", "Nothing.new.empty?", "Nothing.new(1).empty?"]
|
|
20
|
+
},
|
|
21
|
+
"to_string" => {
|
|
22
|
+
name: "to_string",
|
|
23
|
+
description: "returns an empty string for nothing.",
|
|
24
|
+
examples: [
|
|
25
|
+
"nothing.to_string",
|
|
26
|
+
"Nothing.new.to_string",
|
|
27
|
+
"Nothing.new(1).to_string"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"inspect" => {
|
|
31
|
+
name: "inspect",
|
|
32
|
+
description: "returns the source string for nothing.",
|
|
33
|
+
examples: ["nothing.inspect", "Nothing.new.inspect", "Nothing.new(1).inspect"]
|
|
34
|
+
}
|
|
35
|
+
}.freeze
|
|
36
|
+
|
|
37
|
+
def self.function_documentation(scope)
|
|
38
|
+
return INSTANCE_FUNCTIONS if scope == :instance
|
|
39
|
+
|
|
40
|
+
{}
|
|
41
|
+
end
|
|
42
|
+
|
|
6
43
|
def initialize(*_args, **_kargs, &_block)
|
|
7
44
|
self.raw = nil
|
|
8
45
|
end
|
|
9
46
|
|
|
47
|
+
def call(**args)
|
|
48
|
+
code_operator = args.fetch(:operator, nil).to_code
|
|
49
|
+
|
|
50
|
+
case code_operator.to_s
|
|
51
|
+
when "empty?"
|
|
52
|
+
sig(args)
|
|
53
|
+
code_empty?
|
|
54
|
+
else
|
|
55
|
+
super
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
10
59
|
def truthy?
|
|
11
60
|
false
|
|
12
61
|
end
|
|
@@ -19,6 +68,10 @@ class Code
|
|
|
19
68
|
true
|
|
20
69
|
end
|
|
21
70
|
|
|
71
|
+
def code_empty?
|
|
72
|
+
Boolean.new(true)
|
|
73
|
+
end
|
|
74
|
+
|
|
22
75
|
def code_to_string
|
|
23
76
|
String.new
|
|
24
77
|
end
|
data/lib/code/object/number.rb
CHANGED
|
@@ -3,6 +3,116 @@
|
|
|
3
3
|
class Code
|
|
4
4
|
class Object
|
|
5
5
|
class Number < Object
|
|
6
|
+
CLASS_DOCUMENTATION = {
|
|
7
|
+
name: "Number",
|
|
8
|
+
description: "represents numeric behavior shared by integers and decimals.",
|
|
9
|
+
examples: [
|
|
10
|
+
"Number.documentation.name",
|
|
11
|
+
"Number.instance_functions.keys.include?(:between?)",
|
|
12
|
+
"1.5.clamp(0, 1)"
|
|
13
|
+
]
|
|
14
|
+
}.freeze
|
|
15
|
+
INSTANCE_FUNCTIONS = {
|
|
16
|
+
"between?" => {
|
|
17
|
+
name: "between?",
|
|
18
|
+
description: "returns whether the number is within inclusive bounds.",
|
|
19
|
+
examples: ["2.between?(1, 3)", "1.5.between?(1, 2)", "4.between?(1, 3)"]
|
|
20
|
+
},
|
|
21
|
+
"clamp" => {
|
|
22
|
+
name: "clamp",
|
|
23
|
+
description: "returns the number limited to inclusive bounds.",
|
|
24
|
+
examples: ["5.clamp(1, 3)", "0.clamp(1, 3)", "2.5.clamp(1, 3)"]
|
|
25
|
+
},
|
|
26
|
+
"divide" => {
|
|
27
|
+
name: "divide",
|
|
28
|
+
description: "returns floor division of the number by another number.",
|
|
29
|
+
examples: ["5.divide(2)", "10.divide(3)", "9.5.divide(2)"]
|
|
30
|
+
},
|
|
31
|
+
"divide_modulo" => {
|
|
32
|
+
name: "divide_modulo",
|
|
33
|
+
description: "returns floor division and modulo as a list.",
|
|
34
|
+
examples: ["5.divide_modulo(2)", "10.divide_modulo(3)", "9.5.divide_modulo(2)"]
|
|
35
|
+
},
|
|
36
|
+
"next" => {
|
|
37
|
+
name: "next",
|
|
38
|
+
description: "returns the number plus one.",
|
|
39
|
+
examples: ["1.next", "1.5.next", "-1.next"]
|
|
40
|
+
},
|
|
41
|
+
"successor" => {
|
|
42
|
+
name: "successor",
|
|
43
|
+
description: "returns the number plus one, matching next.",
|
|
44
|
+
examples: ["1.successor", "1.5.successor", "-1.successor"]
|
|
45
|
+
},
|
|
46
|
+
"previous" => {
|
|
47
|
+
name: "previous",
|
|
48
|
+
description: "returns the number minus one.",
|
|
49
|
+
examples: ["1.previous", "1.5.previous", "-1.previous"]
|
|
50
|
+
},
|
|
51
|
+
"predecessor" => {
|
|
52
|
+
name: "predecessor",
|
|
53
|
+
description: "returns the number minus one, matching previous.",
|
|
54
|
+
examples: ["1.predecessor", "1.5.predecessor", "-1.predecessor"]
|
|
55
|
+
},
|
|
56
|
+
"remainder" => {
|
|
57
|
+
name: "remainder",
|
|
58
|
+
description: "returns the remainder from division by another number.",
|
|
59
|
+
examples: ["5.remainder(2)", "10.remainder(3)", "9.5.remainder(2)"]
|
|
60
|
+
}
|
|
61
|
+
}.freeze
|
|
62
|
+
|
|
63
|
+
def self.function_documentation(scope)
|
|
64
|
+
return INSTANCE_FUNCTIONS if scope == :instance
|
|
65
|
+
|
|
66
|
+
{}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def code_between?(min, max)
|
|
70
|
+
code_min = min.to_code
|
|
71
|
+
code_max = max.to_code
|
|
72
|
+
|
|
73
|
+
Boolean.new(raw.between?(code_min.raw, code_max.raw))
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def code_clamp(min, max)
|
|
77
|
+
code_min = min.to_code
|
|
78
|
+
code_max = max.to_code
|
|
79
|
+
|
|
80
|
+
self.class.new(raw.clamp(code_min.raw, code_max.raw))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def code_divide(other)
|
|
84
|
+
code_other = other.to_code
|
|
85
|
+
|
|
86
|
+
Integer.new(raw.div(code_other.raw))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def code_divide_modulo(other)
|
|
90
|
+
code_other = other.to_code
|
|
91
|
+
|
|
92
|
+
List.new(raw.divmod(code_other.raw))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def code_next
|
|
96
|
+
code_plus(Integer.new(1))
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def code_previous
|
|
100
|
+
code_minus(Integer.new(1))
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def code_remainder(other)
|
|
104
|
+
code_other = other.to_code
|
|
105
|
+
|
|
106
|
+
self.class.new(raw.remainder(code_other.raw))
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def code_successor
|
|
110
|
+
code_next
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def code_predecessor
|
|
114
|
+
code_previous
|
|
115
|
+
end
|
|
6
116
|
end
|
|
7
117
|
end
|
|
8
118
|
end
|
|
@@ -3,6 +3,138 @@
|
|
|
3
3
|
class Code
|
|
4
4
|
class Object
|
|
5
5
|
class Parameter < Dictionary
|
|
6
|
+
CLASS_DOCUMENTATION = {
|
|
7
|
+
name: "Parameter",
|
|
8
|
+
description: "describes one function parameter with its name, kind flags, and default value.",
|
|
9
|
+
examples: [
|
|
10
|
+
"((name) => { name }).parameters.first",
|
|
11
|
+
"((name:) => { name }).parameters.first.keyword?",
|
|
12
|
+
"((name = :a) => { name }).parameters.first.default"
|
|
13
|
+
]
|
|
14
|
+
}.freeze
|
|
15
|
+
INSTANCE_FUNCTIONS = {
|
|
16
|
+
"name" => {
|
|
17
|
+
name: "name",
|
|
18
|
+
description: "returns the parameter identifier name.",
|
|
19
|
+
examples: [
|
|
20
|
+
"((name) => { name }).parameters.first.name",
|
|
21
|
+
"((name = :a) => { name }).parameters.first.name",
|
|
22
|
+
"((...values) => { values }).parameters.first.name"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"regular?" => {
|
|
26
|
+
name: "regular?",
|
|
27
|
+
description: "returns whether the parameter is not a keyword parameter.",
|
|
28
|
+
examples: [
|
|
29
|
+
"((name) => { name }).parameters.first.regular?",
|
|
30
|
+
"((name:) => { name }).parameters.first.regular?",
|
|
31
|
+
"((...values) => { values }).parameters.first.regular?"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"keyword?" => {
|
|
35
|
+
name: "keyword?",
|
|
36
|
+
description: "returns whether the parameter is a named keyword parameter.",
|
|
37
|
+
examples: [
|
|
38
|
+
"((name:) => { name }).parameters.first.keyword?",
|
|
39
|
+
"((name) => { name }).parameters.first.keyword?",
|
|
40
|
+
"((**options) => { options }).parameters.first.keyword?"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"regular_splat?" => {
|
|
44
|
+
name: "regular_splat?",
|
|
45
|
+
description: "returns whether the parameter captures positional arguments with *.",
|
|
46
|
+
examples: [
|
|
47
|
+
"((...values) => { values }).parameters.first.regular_splat?",
|
|
48
|
+
"((*values) => { values }).parameters.first.regular_splat?",
|
|
49
|
+
"((name) => { name }).parameters.first.regular_splat?"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"keyword_splat?" => {
|
|
53
|
+
name: "keyword_splat?",
|
|
54
|
+
description: "returns whether the parameter captures keyword arguments with **.",
|
|
55
|
+
examples: [
|
|
56
|
+
"((**options) => { options }).parameters.first.keyword_splat?",
|
|
57
|
+
"((name:) => { name }).parameters.first.keyword_splat?",
|
|
58
|
+
"((name) => { name }).parameters.first.keyword_splat?"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"block?" => {
|
|
62
|
+
name: "block?",
|
|
63
|
+
description: "returns whether the parameter captures one function argument with &.",
|
|
64
|
+
examples: [
|
|
65
|
+
"((&block) => { block }).parameters.first.block?",
|
|
66
|
+
"((name) => { name }).parameters.first.block?",
|
|
67
|
+
"((&&blocks) => { blocks }).parameters.first.block?"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"blocks?" => {
|
|
71
|
+
name: "blocks?",
|
|
72
|
+
description: "returns whether the parameter captures remaining function arguments with &&.",
|
|
73
|
+
examples: [
|
|
74
|
+
"((&&blocks) => { blocks }).parameters.first.blocks?",
|
|
75
|
+
"((&block) => { block }).parameters.first.blocks?",
|
|
76
|
+
"((name) => { name }).parameters.first.blocks?"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"spread?" => {
|
|
80
|
+
name: "spread?",
|
|
81
|
+
description: "returns whether the parameter captures every provided argument with spread syntax.",
|
|
82
|
+
examples: [
|
|
83
|
+
"((...values) => { values }).parameters.first.spread?",
|
|
84
|
+
"((name) => { name }).parameters.first.spread?",
|
|
85
|
+
"((name:) => { name }).parameters.first.spread?"
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"required?" => {
|
|
89
|
+
name: "required?",
|
|
90
|
+
description: "returns whether the parameter has no default value.",
|
|
91
|
+
examples: [
|
|
92
|
+
"((name) => { name }).parameters.first.required?",
|
|
93
|
+
"((name = :a) => { name }).parameters.first.required?",
|
|
94
|
+
"((name:) => { name }).parameters.first.required?"
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
"optional?" => {
|
|
98
|
+
name: "optional?",
|
|
99
|
+
description: "returns whether the parameter has a default value.",
|
|
100
|
+
examples: [
|
|
101
|
+
"((name = :a) => { name }).parameters.first.optional?",
|
|
102
|
+
"((name) => { name }).parameters.first.optional?",
|
|
103
|
+
"((name: :a) => { name }).parameters.first.optional?"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
"default" => {
|
|
107
|
+
name: "default",
|
|
108
|
+
description: "returns the default value for the parameter, or nothing when none is set.",
|
|
109
|
+
examples: [
|
|
110
|
+
"((name = :a) => { name }).parameters.first.default",
|
|
111
|
+
"((name) => { name }).parameters.first.default",
|
|
112
|
+
"((name: :a) => { name }).parameters.first.default"
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}.freeze
|
|
116
|
+
|
|
117
|
+
def self.function_documentation(scope)
|
|
118
|
+
return INSTANCE_FUNCTIONS if scope == :instance
|
|
119
|
+
|
|
120
|
+
{}
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def call(**args)
|
|
124
|
+
code_operator = args.fetch(:operator, nil).to_code
|
|
125
|
+
|
|
126
|
+
case code_operator.to_s
|
|
127
|
+
when "required?"
|
|
128
|
+
sig(args)
|
|
129
|
+
code_required?
|
|
130
|
+
when "optional?"
|
|
131
|
+
sig(args)
|
|
132
|
+
code_optional?
|
|
133
|
+
else
|
|
134
|
+
super
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
6
138
|
def code_name
|
|
7
139
|
String.new(code_get(:name))
|
|
8
140
|
end
|
|
@@ -27,6 +159,10 @@ class Code
|
|
|
27
159
|
Boolean.new(code_get(:block?))
|
|
28
160
|
end
|
|
29
161
|
|
|
162
|
+
def code_blocks?
|
|
163
|
+
Boolean.new(code_get(:blocks?))
|
|
164
|
+
end
|
|
165
|
+
|
|
30
166
|
def code_spread?
|
|
31
167
|
Boolean.new(code_get(:spread?))
|
|
32
168
|
end
|
|
@@ -74,6 +210,10 @@ class Code
|
|
|
74
210
|
def block?
|
|
75
211
|
code_block?.truthy?
|
|
76
212
|
end
|
|
213
|
+
|
|
214
|
+
def blocks?
|
|
215
|
+
code_blocks?.truthy?
|
|
216
|
+
end
|
|
77
217
|
end
|
|
78
218
|
end
|
|
79
219
|
end
|