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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8115bfc81c8a3463fefbffc45ec42c3332f97207
4
- data.tar.gz: a95be59582154a4f6c3c513cc5d00d66fe76deca
3
+ metadata.gz: e2ac0ca50e404a1fc715b523bc8b9db45a535408
4
+ data.tar.gz: 10ea5829dd2688d4d8ef0cb99e96698e444e4705
5
5
  SHA512:
6
- metadata.gz: 065c36bb0cd8d3636629364ccbbaeba014199399ca115f036e817b1e13e1031926a232d4caa846e490a5b6ffc13897a9d7bd092da26f834e2db6ed5a0c727a01
7
- data.tar.gz: cac7e40b378bf637481e5d5be154f885a15fb8c4d7a1e22c61ca9e89816f80bde1389b94b63185be6163ff985ccec49fc7d7b512e2e912a01dcefa026d8ba29b
6
+ metadata.gz: 6765c3a9120b8799828308b123b383c8534ef2efeb4be536a3f42416109ca67b984bb435147091fadee23596a3a25e599c832eb7eb185ea3f79f643a0b25c56b
7
+ data.tar.gz: 2a522bc23122290b37ec8f41de2b87206764db9699fb61fc577660fe685accdb93efd468f894d162046fb34975c0516ccff5b4eeec1a7b49e8259ee44d1a9a41
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  *.gem
2
2
  .yardoc
3
3
  doc
4
+ Gemfile.lock
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
- License
164
- -------
163
+ Contributing
164
+ ------------
165
165
 
166
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
167
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
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
- 0. You just DO WHAT THE FUCK YOU WANT TO.
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
- The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
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.
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
  It's this simple:
37
37
 
38
38
  result = EvalIn.call 'puts "hello, world"', language: "ruby/mri-2.1"
39
- result.output # "hello, world\n"
39
+ result.output # "hello, world\\n"
40
40
 
41
41
  DESCRIPTION
42
42
  s.license = "WTFPL"
@@ -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 get_code post_code(code, options)
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
- def self.get_code(location)
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
@@ -1,3 +1,3 @@
1
1
  module EvalIn
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -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 KeyError, /language/
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 'get_code' do
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.get_code "http://example.com/some-result.json"
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.get_code "http://example.com" }.to \
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.get_code 'http://example.com'
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.2
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-24 00:00:00.000000000 Z
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