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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28db53e527baab77e31c69d2ba121f06a91333aa413ac1f82daf5f4f87ba6864
4
- data.tar.gz: '0963f43654020b71820b21fbcc4ade468fa98d85bd5e5fc628bdf5406037508a'
3
+ metadata.gz: 1d1e6240535fbaa53a8402bb09fca25f382435c77b631953da7650279c1779c4
4
+ data.tar.gz: 31ca274073a554129651ad5f6f398ec421bdf34ce20d0953f360b801bb4ba1f4
5
5
  SHA512:
6
- metadata.gz: 61e09ee88f713f2f9dfd3e2f1a6db3ce89ab059170ff9864038e3473d264a36966595b7d354bcc77e3832d8f67620fd44ddf155177e716c0ea841682c64a232b
7
- data.tar.gz: '0806530251411c030f51f3edd620ab7147b98cdbc1712719db0656c5bc9fa9c17b34b92a416432614c046036a327dcefe514cc78e6b5f5026618f2120f536d68'
6
+ metadata.gz: a81a91547923b0bcdca0b971fc0a18a684c439a4bf4821fd4b981afa06d4dbcb7baaf00b4e0e04513a2bc4abbd965b538ab92a7f4cf5739a42d1ffd306c72108
7
+ data.tar.gz: b4135cc2b58e02bde82fe6fb41de533f5c37e0c8ca13bd2507e8c559fb2ebd71b796ab36059c5db0f0a51ca73091c75581136c38a5558e89e0f3ef8341f7a436
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem "rspec"
6
+ gem "ruby-prof"
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
@@ -0,0 +1,3 @@
1
+ # code-ruby
2
+
3
+ A programming language, like `Code.evaluate("1 + 1") # => 2`
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
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.require_paths = ["lib"]
13
13
  s.homepage = "https://github.com/dorianmariefr/code-ruby"
14
14
  s.license = "MIT"
15
+ s.executables = "code"
15
16
 
16
17
  s.add_dependency "zeitwerk", "~> 2"
17
18
  s.add_dependency "language-ruby", "~> 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.0")
3
+ Code::Version = Gem::Version.new("0.6.1")
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.0
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