eval_in 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Readme.md +17 -9
- data/eval_in.gemspec +1 -1
- data/lib/eval_in.rb +10 -5
- data/lib/eval_in/version.rb +1 -1
- data/spec/eval_in_spec.rb +5 -5
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2ac0ca50e404a1fc715b523bc8b9db45a535408
|
4
|
+
data.tar.gz: 10ea5829dd2688d4d8ef0cb99e96698e444e4705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6765c3a9120b8799828308b123b383c8534ef2efeb4be536a3f42416109ca67b984bb435147091fadee23596a3a25e599c832eb7eb185ea3f79f643a0b25c56b
|
7
|
+
data.tar.gz: 2a522bc23122290b37ec8f41de2b87206764db9699fb61fc577660fe685accdb93efd468f894d162046fb34975c0516ccff5b4eeec1a7b49e8259ee44d1a9a41
|
data/.gitignore
CHANGED
data/Readme.md
CHANGED
@@ -157,19 +157,27 @@ Attribution
|
|
157
157
|
|
158
158
|
Thanks to [Charlie Sommerville](https://twitter.com/charliesome) for making eval-in.
|
159
159
|
|
160
|
-
Thanks to Mon Oui, I partially stole the implementation from his gem [cinch-eval-in](http://rubygems.org/gems/cinch-eval-in)
|
160
|
+
Thanks to Mon Oui, I partially stole the first version of the implementation from his gem [cinch-eval-in](http://rubygems.org/gems/cinch-eval-in)
|
161
161
|
|
162
162
|
|
163
|
-
|
164
|
-
|
163
|
+
Contributing
|
164
|
+
------------
|
165
165
|
|
166
|
-
|
167
|
-
|
166
|
+
Fork it, make your changes, send me a pull request.
|
167
|
+
Make sure your code is tested and all tests pass.
|
168
168
|
|
169
|
-
|
169
|
+
Run tests with `bundle exec rspec`, run integration tests with `bundle exec rspec -t integration`.
|
170
|
+
|
171
|
+
|
172
|
+
<a href="http://www.wtfpl.net/"><img src="http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl.svg" height="20" alt="WTFPL" /></a> License
|
173
|
+
-------
|
170
174
|
|
171
|
-
No Warranty
|
172
|
-
-----------
|
173
175
|
|
174
|
-
|
176
|
+
Copyright (C) 2014 Josh Cheek <josh.cheek@gmail.com>
|
175
177
|
|
178
|
+
This program is free software. It comes without any warranty,
|
179
|
+
to the extent permitted by applicable law.
|
180
|
+
You can redistribute it and/or modify it under the terms of the
|
181
|
+
Do What The Fuck You Want To Public License,
|
182
|
+
Version 2, as published by Sam Hocevar.
|
183
|
+
See http://www.wtfpl.net/ for more details.
|
data/eval_in.gemspec
CHANGED
data/lib/eval_in.rb
CHANGED
@@ -58,22 +58,25 @@ module EvalIn
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
# The primary way to use this library.
|
62
|
-
#
|
63
61
|
# @param code [String] the code to evaluate.
|
64
62
|
# @option options [String] :language Mandatory, a language recognized by eval.in, such as any value in {KNOWN_LANGUAGES}.
|
65
63
|
# @option options [String] :url Override the url to post the code to
|
66
64
|
# @option options [String] :stdin Will be passed as standard input to the script
|
67
65
|
# @option options [String] :context Will be included in the user agent
|
68
66
|
# @return [Result] the relevant data from the evaluated code.
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# result = EvalIn.call 'puts "hello, #{gets}"', stdin: 'world', language: "ruby/mri-2.1"
|
70
|
+
# result.output # => "hello, world\n"
|
69
71
|
def self.call(code, options={})
|
70
|
-
build_result
|
72
|
+
build_result fetch_result_json post_code(code, options)
|
71
73
|
end
|
72
74
|
|
75
|
+
# @api private
|
73
76
|
def self.post_code(code, options)
|
74
77
|
uri = URI(options.fetch(:url, "https://eval.in/"))
|
75
78
|
input = options.fetch(:stdin, "")
|
76
|
-
language = options.fetch(:language)
|
79
|
+
language = options.fetch(:language) { raise ArgumentError, ":language is mandatory, but options only has #{options.keys.inspect}" }
|
77
80
|
user_agent = 'http://rubygems.org/gems/eval_in'
|
78
81
|
user_agent << " (#{options[:context]})" if options[:context]
|
79
82
|
path = uri.path
|
@@ -102,7 +105,8 @@ module EvalIn
|
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
105
|
-
|
108
|
+
# @api private
|
109
|
+
def self.fetch_result_json(location)
|
106
110
|
if body = Net::HTTP.get(URI location)
|
107
111
|
JSON.parse(body).merge('url' => location)
|
108
112
|
else
|
@@ -110,6 +114,7 @@ module EvalIn
|
|
110
114
|
end
|
111
115
|
end
|
112
116
|
|
117
|
+
# @api private
|
113
118
|
def self.build_result(response_json)
|
114
119
|
status = response_json['status']
|
115
120
|
exitstatus = if !status then nil # let it choose default
|
data/lib/eval_in/version.rb
CHANGED
data/spec/eval_in_spec.rb
CHANGED
@@ -162,7 +162,7 @@ RSpec.describe 'post_code' do
|
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'raises an ArgumentError error if not given a language' do
|
165
|
-
expect { EvalIn.post_code code, {} }.to raise_error
|
165
|
+
expect { EvalIn.post_code code, {} }.to raise_error ArgumentError, /language/
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'can override the url' do
|
@@ -194,7 +194,7 @@ end
|
|
194
194
|
|
195
195
|
|
196
196
|
|
197
|
-
RSpec.describe '
|
197
|
+
RSpec.describe 'fetch_result_json' do
|
198
198
|
include WebMock::API
|
199
199
|
|
200
200
|
def stub_eval_in(options={})
|
@@ -208,19 +208,19 @@ RSpec.describe 'get_code' do
|
|
208
208
|
|
209
209
|
it 'queries the location, and inflates the json' do
|
210
210
|
stub_eval_in(url: "http://example.com/some-result.json")
|
211
|
-
result = EvalIn.
|
211
|
+
result = EvalIn.fetch_result_json "http://example.com/some-result.json"
|
212
212
|
expect(result).to match hash_including(ruby_result)
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'raises an error when it gets a non-200' do
|
216
216
|
stub_eval_in json_result: '', url: 'http://example.com'
|
217
|
-
expect { EvalIn.
|
217
|
+
expect { EvalIn.fetch_result_json "http://example.com" }.to \
|
218
218
|
raise_error EvalIn::ResultNotFound, %r(http://example.com)
|
219
219
|
end
|
220
220
|
|
221
221
|
it 'adds the url to the result' do
|
222
222
|
stub_eval_in url: 'http://example.com'
|
223
|
-
result = EvalIn.
|
223
|
+
result = EvalIn.fetch_result_json 'http://example.com'
|
224
224
|
expect(result['url']).to eq 'http://example.com'
|
225
225
|
end
|
226
226
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eval_in
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cheek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -65,8 +65,7 @@ description: |+
|
|
65
65
|
It's this simple:
|
66
66
|
|
67
67
|
result = EvalIn.call 'puts "hello, world"', language: "ruby/mri-2.1"
|
68
|
-
result.output # "hello, world
|
69
|
-
"
|
68
|
+
result.output # "hello, world\n"
|
70
69
|
|
71
70
|
email:
|
72
71
|
- josh.cheek@gmail.com
|