code-ruby 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.md +3 -0
- data/bin/code +94 -0
- data/code-ruby.gemspec +1 -0
- data/lib/code/version.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: 1d1e6240535fbaa53a8402bb09fca25f382435c77b631953da7650279c1779c4
|
4
|
+
data.tar.gz: 31ca274073a554129651ad5f6f398ec421bdf34ce20d0953f360b801bb4ba1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a81a91547923b0bcdca0b971fc0a18a684c439a4bf4821fd4b981afa06d4dbcb7baaf00b4e0e04513a2bc4abbd965b538ab92a7f4cf5739a42d1ffd306c72108
|
7
|
+
data.tar.gz: b4135cc2b58e02bde82fe6fb41de533f5c37e0c8ca13bd2507e8c559fb2ebd71b796ab36059c5db0f0a51ca73091c75581136c38a5558e89e0f3ef8341f7a436
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -24,6 +24,7 @@ GEM
|
|
24
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
25
|
rspec-support (~> 3.12.0)
|
26
26
|
rspec-support (3.12.1)
|
27
|
+
ruby-prof (1.6.3)
|
27
28
|
zeitwerk (2.6.12)
|
28
29
|
|
29
30
|
PLATFORMS
|
@@ -32,6 +33,7 @@ PLATFORMS
|
|
32
33
|
DEPENDENCIES
|
33
34
|
code-ruby!
|
34
35
|
rspec
|
36
|
+
ruby-prof
|
35
37
|
|
36
38
|
BUNDLED WITH
|
37
39
|
2.4.22
|
data/README.md
ADDED
data/bin/code
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require_relative "../lib/code-ruby"
|
5
|
+
|
6
|
+
options = { timeout: 0, profile: false, profiler: "text" }
|
7
|
+
|
8
|
+
OptionParser
|
9
|
+
.new do |opts|
|
10
|
+
opts.banner = "Usage: template [options]"
|
11
|
+
|
12
|
+
opts.on(
|
13
|
+
"-v",
|
14
|
+
"--version",
|
15
|
+
"Version of template"
|
16
|
+
) do |input|
|
17
|
+
puts Code::Version
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on(
|
22
|
+
"-i INPUT",
|
23
|
+
"--input=INPUT",
|
24
|
+
"Input in the code language (String or File)"
|
25
|
+
) do |input|
|
26
|
+
input = File.read(input) if File.exist?(input)
|
27
|
+
|
28
|
+
options[:input] = input
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on(
|
32
|
+
"-c CONTEXT",
|
33
|
+
"--context=CONTEXT",
|
34
|
+
"Context in the code language (String or File)"
|
35
|
+
) do |context|
|
36
|
+
context = File.read(context) if File.exist?(context)
|
37
|
+
|
38
|
+
options[:context] = context
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-p", "--parse", "Get parser results for input") do |parse|
|
42
|
+
options[:parse] = parse
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on(
|
46
|
+
"-t TIMEOUT",
|
47
|
+
"--timeout=TIMEOUT",
|
48
|
+
"Set timeout in seconds"
|
49
|
+
) { |timeout| options[:timeout] = timeout.to_f }
|
50
|
+
|
51
|
+
opts.on(
|
52
|
+
"--profile",
|
53
|
+
"Profile Ruby code"
|
54
|
+
) do |timeout|
|
55
|
+
require "ruby-prof"
|
56
|
+
options[:profile] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on(
|
60
|
+
"--profiler TYPE",
|
61
|
+
"Profiler output type (text (default) or html)"
|
62
|
+
) do |profiler|
|
63
|
+
require "ruby-prof"
|
64
|
+
options[:profile] = true
|
65
|
+
options[:profiler] = profiler
|
66
|
+
end
|
67
|
+
end
|
68
|
+
.parse!
|
69
|
+
|
70
|
+
input = options.fetch(:input, "")
|
71
|
+
context = options.fetch(:context, "")
|
72
|
+
|
73
|
+
if options[:profile]
|
74
|
+
RubyProf.start
|
75
|
+
end
|
76
|
+
|
77
|
+
if options[:parse]
|
78
|
+
pp Code::Parser.parse(input).to_raw
|
79
|
+
else
|
80
|
+
print Code.evaluate(input, context, io: $stdout, timeout: options[:timeout])
|
81
|
+
end
|
82
|
+
|
83
|
+
if options[:profile]
|
84
|
+
result = RubyProf.stop
|
85
|
+
if options[:profiler] == "text"
|
86
|
+
printer = RubyProf::FlatPrinter.new(result)
|
87
|
+
printer.print($stdout)
|
88
|
+
elsif options[:profiler] == "html"
|
89
|
+
printer = RubyProf::GraphHtmlPrinter.new(result)
|
90
|
+
printer.print($stdout)
|
91
|
+
else
|
92
|
+
abort "#{options[:profiler]} not recognized"
|
93
|
+
end
|
94
|
+
end
|
data/code-ruby.gemspec
CHANGED
data/lib/code/version.rb
CHANGED
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: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
@@ -40,13 +40,16 @@ dependencies:
|
|
40
40
|
version: '0'
|
41
41
|
description: 'A programming language, like Code.evaluate("1 + 1") # => 2'
|
42
42
|
email: dorian@dorianmarie.fr
|
43
|
-
executables:
|
43
|
+
executables:
|
44
|
+
- code
|
44
45
|
extensions: []
|
45
46
|
extra_rdoc_files: []
|
46
47
|
files:
|
47
48
|
- ".rspec"
|
48
49
|
- Gemfile
|
49
50
|
- Gemfile.lock
|
51
|
+
- README.md
|
52
|
+
- bin/code
|
50
53
|
- code-ruby.gemspec
|
51
54
|
- lib/code-ruby.rb
|
52
55
|
- lib/code.rb
|