ruby-eval-in 0.0.3 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +30 -3
- data/README.md +2 -1
- data/lib/eval-in.rb +15 -14
- data/lib/eval-in/exceptions.rb +23 -21
- data/lib/eval-in/result.rb +71 -74
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1886aec828d9dc629c2638c9c5af5d6700ddb2d069f048fcc7ce5ea99e35f633
|
4
|
+
data.tar.gz: 23f723ee4fa45327f5aa8126ce76ef8b461ac1e1fc56dfc22f224526353bef9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 382700474e8545c199c3f8d52b3420ebcb80eaed956fcb357e38b17fb60904798c2fb50fad95af449684220fd33232f78368b255ce75faabe1bb3b3d5fdcd339
|
7
|
+
data.tar.gz: 7a070fa3b4a84d14d7da47aaf4ba83625cc2735e604742abd466cc73df5774c8745e620c2009feff0dc09d40d34e7235baf91e0159b59bdfc6e5188bad1a073a
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
The MIT License (MIT)
|
1
|
+
The MIT License (MIT) with restrictions
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2020 William Woodruff <william @ yossarian.net>
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -18,4 +18,31 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
23
|
+
The following terms additionally apply and override any above terms for
|
24
|
+
applicable parties:
|
25
|
+
|
26
|
+
You may not use, copy, modify, merge, publish, distribute, sublicense,
|
27
|
+
and/or sell copies of the Software in a military or law enforcement context,
|
28
|
+
defined as follows:
|
29
|
+
|
30
|
+
1. A military context is a professional context where the intended application
|
31
|
+
of the Software is integration or use with or by military software, tools
|
32
|
+
(software or hardware), or personnel. This includes contractors and
|
33
|
+
subcontractors as well as research affiliates of any military organization.
|
34
|
+
|
35
|
+
2. A law enforcement context is a professional context where the intended
|
36
|
+
application of the Software is integration or use with or by law enforcement
|
37
|
+
software, tools (software or hardware), or personnel. This includes
|
38
|
+
contractors and subcontractors as well as research affiliates of any law
|
39
|
+
enforcement organization.
|
40
|
+
|
41
|
+
Entities that sell or license to military or law enforcement organizations
|
42
|
+
may use the Software under the original terms, but only in contexts that do
|
43
|
+
not assist or supplement the sold or licensed product.
|
44
|
+
|
45
|
+
Students and academics who are affiliated with research institutions may use
|
46
|
+
the Software under the original terms, but only in contexts that do not assist
|
47
|
+
or supplement collaboration or affiliation with any military or law
|
48
|
+
enforcement organization.
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
ruby-eval-in
|
2
2
|
============
|
3
3
|
|
4
|
+
![license](https://raster.shields.io/badge/license-MIT%20with%20restrictions-green.png)
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/ruby-eval-in.svg)](http://badge.fury.io/rb/ruby-eval-in)
|
5
|
-
[![Build Status](https://
|
6
|
+
[![Build Status](https://travis-ci.org/woodruffw/ruby-eval-in.svg?branch=master)](https://travis-ci.org/woodruffw/ruby-eval-in)
|
6
7
|
|
7
8
|
A basic Ruby interface to the [eval.in](https://eval.in) online evaluation
|
8
9
|
service.
|
data/lib/eval-in.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
#
|
2
|
-
# Author: William Woodruff
|
3
|
-
# A Ruby interface to the eval.in (https://eval.in) service.
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
require_relative "eval-in/result"
|
4
|
+
require_relative "eval-in/exceptions"
|
7
5
|
|
8
6
|
# The primary namespace.
|
9
7
|
# @author William Woodruff
|
10
8
|
# @since 0.0.1
|
11
9
|
module EvalIn
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
# The library's current version.
|
11
|
+
VERSION = "0.0.8"
|
12
|
+
|
13
|
+
# Evaluate some code in a given language.
|
14
|
+
# @example
|
15
|
+
# EvalIn.eval(:ruby, 'puts "Hello, World"') # => #<EvalIn::Result:0xNN>
|
16
|
+
# @param [Symbol, String] lang the language to execute in
|
17
|
+
# @param [String] code the program code to execute
|
18
|
+
# @return [EvalIn::Result] the execution results
|
19
|
+
def self.eval(lang, code)
|
20
|
+
EvalIn::Result.new(lang.to_s.downcase, code)
|
21
|
+
end
|
21
22
|
end
|
data/lib/eval-in/exceptions.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module EvalIn
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
# A parent Error class for all eval-in errors.
|
5
|
+
class EvalInError < RuntimeError
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
# Raised when an error occurs during connection.
|
9
|
+
class ConnectionError < EvalInError
|
10
|
+
def initialize(error)
|
11
|
+
super "Connection error: #{error}"
|
12
|
+
end
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
# Raised when EvalIn.{EvalIn.eval} is given a bad input language.
|
16
|
+
class BadLanguageError < EvalInError
|
17
|
+
def initialize(lang)
|
18
|
+
super "No such language: #{lang}"
|
19
|
+
end
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
# Raised when EvalIn.{EvalIn.eval} is given blank or whitespace-only code.
|
23
|
+
class EmptyCodeError < EvalInError
|
24
|
+
def initialize
|
25
|
+
super "The code may not be empty"
|
26
|
+
end
|
27
|
+
end
|
26
28
|
end
|
data/lib/eval-in/result.rb
CHANGED
@@ -1,89 +1,86 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
4
6
|
|
5
7
|
module EvalIn
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
# A representation of a result produced by an eval.in query.
|
9
|
+
class Result
|
10
|
+
# @private
|
11
|
+
URL = URI("https://eval.in")
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
# The languages supported by eval.in.
|
14
|
+
# Any of these keys or values will work for the lang parameter in
|
15
|
+
# {EvalIn.eval}.
|
16
|
+
LANGS = {
|
17
|
+
"c" => "c/gcc-4.9.1",
|
18
|
+
"c++" => "c++/gcc-4.9.1",
|
19
|
+
"coffeescript" => "coffeescript/node-0.10.29-coffee-1.7.1",
|
20
|
+
"fortran" => "fortran/f95-4.4.3",
|
21
|
+
"haskell" => "haskell/hugs98-sep-2006",
|
22
|
+
"io" => "io/io-20131204",
|
23
|
+
"js" => "javascript/node-0.10.29",
|
24
|
+
"lua" => "lua/lua-5.2.3",
|
25
|
+
"ocaml" => "ocaml/ocaml-4.01.0",
|
26
|
+
"php5" => "php/php-5.6.23",
|
27
|
+
"php7" => "php/php-7.0.8",
|
28
|
+
"pascal" => "pascal/fpc-2.6.4",
|
29
|
+
"perl" => "perl/perl-5.20.0",
|
30
|
+
"python" => "python/cpython-3.4.1",
|
31
|
+
"python2" => "python/cpython-2.7.8",
|
32
|
+
"racket" => "racket/racket-6.10.1",
|
33
|
+
"ruby" => "ruby/mri-2.4",
|
34
|
+
"slash" => "slash/slash-head",
|
35
|
+
"nasm" => "assembly/nasm-2.07",
|
36
|
+
}.freeze
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
# @return [String] the expanded language used in execution
|
39
|
+
# @example
|
40
|
+
# result.language # => "ruby/mri-2.2"
|
41
|
+
attr_reader :language
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
# @return [String] the program code used in execution
|
44
|
+
# @example
|
45
|
+
# result.code # => "puts \"hello\""
|
46
|
+
attr_reader :code
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
# @return [String] any output produced by the program
|
49
|
+
# @example
|
50
|
+
# result.output # => "hello\n"
|
51
|
+
attr_reader :output
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
# @return [String] the program's exit status
|
54
|
+
# @example
|
55
|
+
# result.status # => "OK (0 sec real, 0 sec wall, 8 MB, 16 syscalls)"
|
56
|
+
attr_reader :status
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
# @return [URI] a permalink to the output webpage
|
59
|
+
# @example
|
60
|
+
# result.url # => #<URI::HTTPS https://eval.in/xxxxxx>
|
61
|
+
attr_reader :url
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
# @private
|
64
|
+
def initialize(lang, code)
|
65
|
+
if LANGS.key?(lang)
|
66
|
+
lang = LANGS[lang]
|
67
|
+
elsif !LANGS.value?(lang)
|
68
|
+
raise BadLanguageError, lang
|
69
|
+
end
|
66
70
|
|
67
|
-
|
71
|
+
raise EmptyCodeError if code.strip.empty?
|
68
72
|
|
69
|
-
|
70
|
-
|
73
|
+
@lang = lang
|
74
|
+
@code = code
|
71
75
|
|
72
|
-
|
73
|
-
"execute" => "on",
|
74
|
-
"lang" => lang,
|
75
|
-
"code" => code
|
76
|
-
)
|
76
|
+
result = Net::HTTP.post_form(URL, "execute" => "on", "lang" => lang, "code" => code)
|
77
77
|
|
78
|
-
|
79
|
-
@url = URI(result["location"])
|
78
|
+
raise ConnectionError, result unless result.is_a? Net::HTTPFound
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
80
|
+
@url = URI(result["location"])
|
81
|
+
html = Nokogiri::HTML(Net::HTTP.get(@url))
|
82
|
+
@output = html.css("pre").last.text
|
83
|
+
@status = html.css("p")[1].text
|
84
|
+
end
|
85
|
+
end
|
89
86
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-eval-in
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: A Ruby interface to https://eval.in/.
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- lib/eval-in/result.rb
|
41
41
|
homepage: https://github.com/woodruffw/ruby-eval-in
|
42
42
|
licenses:
|
43
|
-
-
|
43
|
+
- Nonstandard
|
44
44
|
metadata: {}
|
45
45
|
post_install_message:
|
46
46
|
rdoc_options: []
|
@@ -50,15 +50,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.
|
53
|
+
version: '2.3'
|
54
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
|
-
|
61
|
-
rubygems_version: 2.4.5.1
|
60
|
+
rubygems_version: 3.1.2
|
62
61
|
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: ruby-eval-in - A Ruby interface to https://eval.in/.
|