code-ruby 0.6.2 → 0.6.3
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/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -1
- data/bin/code +3 -12
- data/lib/code/object/dictionary.rb +15 -3
- data/lib/code/object/function.rb +5 -4
- data/lib/code/object/string.rb +1 -1
- data/lib/code/type/hash.rb +3 -7
- data/lib/code/type/sig.rb +10 -4
- data/lib/code/version.rb +1 -1
- data/spec/code/object/function_spec.rb +2 -2
- data/spec/code/object/list_spec.rb +1 -4
- data/spec/code_spec.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ab3a0f0749357d4065315d58b613f8d44cba5f567b6ae33444cff90c1dedde0
|
4
|
+
data.tar.gz: b48a0d5c713c0eb33c53bd30fafaaa7bc03f657a7ac7a5c70ae257eedf677cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e137c317b1d87a1a61d30ce70d4bccdd75417ab002c6ad57249081f2e8b8189e4194efaad6e277f68448fa8f55b1402e337d5387d34449b69fce4425b17d72e7
|
7
|
+
data.tar.gz: 2bdfced46d44b0ef4787a998fb17ce073b38a939d044a9f48f39c74dc42adbec3962622792f9852579203f090a66db78dc45aa118d25ff325089cde03cb00c93
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.3.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/bin/code
CHANGED
@@ -9,11 +9,7 @@ OptionParser
|
|
9
9
|
.new do |opts|
|
10
10
|
opts.banner = "Usage: template [options]"
|
11
11
|
|
12
|
-
opts.on(
|
13
|
-
"-v",
|
14
|
-
"--version",
|
15
|
-
"Version of template"
|
16
|
-
) do |input|
|
12
|
+
opts.on("-v", "--version", "Version of template") do |input|
|
17
13
|
puts Code::Version
|
18
14
|
exit
|
19
15
|
end
|
@@ -48,10 +44,7 @@ OptionParser
|
|
48
44
|
"Set timeout in seconds"
|
49
45
|
) { |timeout| options[:timeout] = timeout.to_f }
|
50
46
|
|
51
|
-
opts.on(
|
52
|
-
"--profile",
|
53
|
-
"Profile Ruby code"
|
54
|
-
) do |timeout|
|
47
|
+
opts.on("--profile", "Profile Ruby code") do |timeout|
|
55
48
|
require "ruby-prof"
|
56
49
|
options[:profile] = true
|
57
50
|
end
|
@@ -70,9 +63,7 @@ OptionParser
|
|
70
63
|
input = options.fetch(:input, "")
|
71
64
|
context = options.fetch(:context, "")
|
72
65
|
|
73
|
-
if options[:profile]
|
74
|
-
RubyProf.start
|
75
|
-
end
|
66
|
+
RubyProf.start if options[:profile]
|
76
67
|
|
77
68
|
if options[:parse]
|
78
69
|
pp Code::Parser.parse(input).to_raw
|
@@ -214,7 +214,11 @@ class Code
|
|
214
214
|
|
215
215
|
def code_delete(*arguments, index: Integer.new(0), **globals)
|
216
216
|
default =
|
217
|
-
(
|
217
|
+
(
|
218
|
+
if arguments.last.is_a?(Function) && arguments.size > 1
|
219
|
+
arguments.last
|
220
|
+
end
|
221
|
+
)
|
218
222
|
|
219
223
|
arguments = arguments[..-2] if default
|
220
224
|
|
@@ -337,7 +341,11 @@ class Code
|
|
337
341
|
|
338
342
|
def code_fetch(*arguments, index: Integer.new(0), **globals)
|
339
343
|
default =
|
340
|
-
(
|
344
|
+
(
|
345
|
+
if arguments.last.is_a?(Function) && arguments.size > 1
|
346
|
+
arguments.last
|
347
|
+
end
|
348
|
+
)
|
341
349
|
|
342
350
|
arguments = arguments[..-2] if default
|
343
351
|
|
@@ -485,7 +493,11 @@ class Code
|
|
485
493
|
|
486
494
|
def code_merge(*arguments, **globals)
|
487
495
|
conflict =
|
488
|
-
(
|
496
|
+
(
|
497
|
+
if arguments.last.is_a?(Function) && arguments.size > 1
|
498
|
+
arguments.last
|
499
|
+
end
|
500
|
+
)
|
489
501
|
|
490
502
|
arguments = arguments[..-2] if conflict
|
491
503
|
|
data/lib/code/object/function.rb
CHANGED
@@ -36,9 +36,7 @@ class Code
|
|
36
36
|
if parameter.regular_splat?
|
37
37
|
context.code_set(
|
38
38
|
parameter.name,
|
39
|
-
List.new(
|
40
|
-
arguments.select(&:regular?).map(&:value)
|
41
|
-
)
|
39
|
+
List.new(arguments.select(&:regular?).map(&:value))
|
42
40
|
)
|
43
41
|
elsif parameter.keyword_splat?
|
44
42
|
context.code_set(
|
@@ -53,7 +51,10 @@ class Code
|
|
53
51
|
context.code_set(parameter.name, argument)
|
54
52
|
end
|
55
53
|
elsif parameter.keyword?
|
56
|
-
argument =
|
54
|
+
argument =
|
55
|
+
arguments
|
56
|
+
.detect { |argument| argument.name == parameter.name }
|
57
|
+
&.value
|
57
58
|
argument = parameter.evaluate(**globals) if argument.nil?
|
58
59
|
context.code_set(parameter.name, argument)
|
59
60
|
else
|
data/lib/code/object/string.rb
CHANGED
data/lib/code/type/hash.rb
CHANGED
@@ -6,7 +6,7 @@ class Code
|
|
6
6
|
attr_reader :hash
|
7
7
|
|
8
8
|
def initialize(hash)
|
9
|
-
@hash = hash
|
9
|
+
@hash = hash.transform_keys { |key| Object::String.new(key) }
|
10
10
|
end
|
11
11
|
|
12
12
|
def valid?(argument)
|
@@ -19,15 +19,11 @@ class Code
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def min_arguments
|
22
|
-
hash.sum
|
23
|
-
min_arguments_of(value)
|
24
|
-
end
|
22
|
+
hash.sum { |_, value| min_arguments_of(value) }
|
25
23
|
end
|
26
24
|
|
27
25
|
def max_arguments
|
28
|
-
hash.sum
|
29
|
-
max_arguments_of(value)
|
30
|
-
end
|
26
|
+
hash.sum { |_, value| max_arguments_of(value) }
|
31
27
|
end
|
32
28
|
|
33
29
|
def name
|
data/lib/code/type/sig.rb
CHANGED
@@ -23,9 +23,10 @@ class Code
|
|
23
23
|
attr_reader :args, :block, :object
|
24
24
|
|
25
25
|
def expected_arguments
|
26
|
-
@expected_arguments ||=
|
27
|
-
|
28
|
-
|
26
|
+
@expected_arguments ||=
|
27
|
+
wrap(block&.call || []).map do |clazz|
|
28
|
+
clazz.is_a?(::Hash) ? Hash.new(clazz) : clazz
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
32
|
def min_arguments_of(clazz)
|
@@ -53,7 +54,8 @@ class Code
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def max_arguments
|
56
|
-
max_arguments =
|
57
|
+
max_arguments =
|
58
|
+
expected_arguments.map { |clazz| max_arguments_of(clazz) }
|
57
59
|
max_arguments.include?(nil) ? nil : max_arguments.sum
|
58
60
|
end
|
59
61
|
|
@@ -96,6 +98,10 @@ class Code
|
|
96
98
|
expected.is_a?(Type) ? expected.valid?(actual) : actual.is_a?(expected)
|
97
99
|
end
|
98
100
|
|
101
|
+
def wrap(object)
|
102
|
+
object.is_a?(Array) ? object : [object]
|
103
|
+
end
|
104
|
+
|
99
105
|
def check_types_of_arguments!
|
100
106
|
expected_index = 0
|
101
107
|
repeat_index = 0
|
data/lib/code/version.rb
CHANGED
@@ -19,8 +19,8 @@ RSpec.describe Code::Object::Function do
|
|
19
19
|
context "valid" do
|
20
20
|
[
|
21
21
|
"f = () => {} f",
|
22
|
-
"f = (x) => {} f(1)"
|
23
|
-
# "f = (x:) => {} f(x: 1)"
|
22
|
+
"f = (x) => {} f(1)"
|
23
|
+
# "f = (x:) => {} f(x: 1)"
|
24
24
|
].each do |input|
|
25
25
|
it "#{input} is valid" do
|
26
26
|
Code.evaluate(input)
|
@@ -3,10 +3,7 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Code::Object::List do
|
6
|
-
[
|
7
|
-
["[] == []", "true"],
|
8
|
-
["[1, 2, 3].sum", "6"],
|
9
|
-
].each do |input, expected|
|
6
|
+
[["[] == []", "true"], ["[1, 2, 3].sum", "6"]].each do |input, expected|
|
10
7
|
it "#{input} == #{expected}" do
|
11
8
|
expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
12
9
|
end
|
data/spec/code_spec.rb
CHANGED
@@ -109,7 +109,7 @@ RSpec.describe Code do
|
|
109
109
|
['"Hello \\{name}"', '"Hello \\{" + "name}"'],
|
110
110
|
["'Hello {1}'", '"Hello 1"'],
|
111
111
|
['"Hello {1}"', '"Hello 1"'],
|
112
|
-
|
112
|
+
[":Hello.include?(a: :H)", true],
|
113
113
|
%w["Hello".downcase :hello],
|
114
114
|
["true ? 1", "1"],
|
115
115
|
["false ? 1", ""],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -59,7 +59,10 @@ executables:
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".gitignore"
|
62
63
|
- ".rspec"
|
64
|
+
- ".ruby-version"
|
65
|
+
- ".tool-versions"
|
63
66
|
- Gemfile
|
64
67
|
- Gemfile.lock
|
65
68
|
- README.md
|