code-ruby 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b63a5dc762c3ac1d5e2f37910c24806b092a78f0bc8ed5ad4409f2e6283f7880
4
- data.tar.gz: 5cd2966db552e1b06a7946767af43005a670dbe76378e8680524af6abf3a2479
3
+ metadata.gz: 7ab3a0f0749357d4065315d58b613f8d44cba5f567b6ae33444cff90c1dedde0
4
+ data.tar.gz: b48a0d5c713c0eb33c53bd30fafaaa7bc03f657a7ac7a5c70ae257eedf677cc0
5
5
  SHA512:
6
- metadata.gz: 7d364133a93859542602ac10730d4b539e2e090e7b91fa9ffacfec1602edc5701da4ab8c6d1208e6e9a1967983ea2c62d80fbf7aab6df62141da332199ed7796
7
- data.tar.gz: ad10fe135a0391fa37d769282b13a1fa7b1423a9226daa147553d91ee0d61f03f8b49d6e7b1c0514709bbf0cb03fe6c64db9ea7a71b10b9761cdcc1cdc95f2a1
6
+ metadata.gz: e137c317b1d87a1a61d30ce70d4bccdd75417ab002c6ad57249081f2e8b8189e4194efaad6e277f68448fa8f55b1402e337d5387d34449b69fce4425b17d72e7
7
+ data.tar.gz: 2bdfced46d44b0ef4787a998fb17ce073b38a939d044a9f48f39c74dc42adbec3962622792f9852579203f090a66db78dc45aa118d25ff325089cde03cb00c93
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ .env
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
@@ -2,5 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
+ ruby "3.3.0"
6
+
5
7
  gem "rspec"
6
8
  gem "ruby-prof"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (0.6.1)
4
+ code-ruby (0.6.2)
5
5
  bigdecimal (~> 3)
6
6
  language-ruby (~> 0)
7
7
  zeitwerk (~> 2)
@@ -38,5 +38,8 @@ DEPENDENCIES
38
38
  rspec
39
39
  ruby-prof
40
40
 
41
+ RUBY VERSION
42
+ ruby 3.3.0p0
43
+
41
44
  BUNDLED WITH
42
45
  2.5.5
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
- (arguments.last if arguments.last.is_a?(Function) && arguments.size > 1)
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
- (arguments.last if arguments.last.is_a?(Function) && arguments.size > 1)
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
- (arguments.last if arguments.last.is_a?(Function) && arguments.size > 1)
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
 
@@ -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 = arguments.detect { |argument| argument.name == parameter.name }&.value
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
@@ -33,7 +33,7 @@ class Code
33
33
  sig(args)
34
34
  code_downcase
35
35
  when "include?"
36
- sig(args) { String }
36
+ sig(args) { { a: String } }
37
37
  code_include?(value)
38
38
  when "reverse"
39
39
  sig(args)
@@ -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 do |_, value|
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 do |_, value|
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 ||= Array(block&.call || []).map do |clazz|
27
- clazz.is_a?(::Hash) ? Hash.new(clazz) : clazz
28
- end
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 = expected_arguments.map { |clazz| max_arguments_of(clazz) }
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
@@ -1,3 +1,3 @@
1
1
  require_relative "../code"
2
2
 
3
- Code::Version = Gem::Version.new("0.6.2")
3
+ Code::Version = Gem::Version.new("0.6.3")
@@ -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
- %w["Hello".include?("H") true],
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.2
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-30 00:00:00.000000000 Z
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