hirobumi-with_ruby 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/with_ruby/version.rb +1 -1
- data/lib/with_ruby.rb +11 -2
- data/test/unit/with_ruby_test.rb +13 -2
- metadata +2 -2
data/lib/with_ruby/version.rb
CHANGED
data/lib/with_ruby.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
|
3
|
+
require 'yaml'
|
4
|
+
|
3
5
|
module WithRuby
|
4
6
|
|
5
7
|
class << self
|
6
8
|
|
7
9
|
def run(options = {})
|
8
|
-
bin = options.delete('bin') || '/usr/bin/env ruby -Ku
|
10
|
+
bin = options.delete('bin') || '/usr/bin/env ruby -Ku'
|
9
11
|
|
10
12
|
command = yield.to_s
|
11
13
|
|
@@ -14,17 +16,24 @@ module WithRuby
|
|
14
16
|
io.puts(build(command, options))
|
15
17
|
ret = YAML.load(io.read)
|
16
18
|
end
|
19
|
+
|
20
|
+
raise(ret) if ret.is_a?(Exception)
|
17
21
|
|
18
22
|
ret
|
19
23
|
end
|
20
24
|
|
21
25
|
def build(command, options)
|
26
|
+
"require 'rubygems'\n" +
|
22
27
|
"require 'yaml'\n" +
|
23
28
|
"def __with_ruby\n" +
|
24
29
|
build_params(options) +
|
25
30
|
command +
|
26
31
|
"end\n" +
|
27
|
-
"
|
32
|
+
"begin\n" +
|
33
|
+
" STDOUT.puts(YAML.dump(__with_ruby))\n" +
|
34
|
+
"rescue Exception => boom\n" +
|
35
|
+
" STDOUT.puts(YAML.dump(boom))\n" +
|
36
|
+
"end\n" +
|
28
37
|
"__END__"
|
29
38
|
end
|
30
39
|
|
data/test/unit/with_ruby_test.rb
CHANGED
@@ -23,16 +23,27 @@ class WithRubyTest < Test::Unit::TestCase
|
|
23
23
|
should 'be able to handle Hpricot' do
|
24
24
|
text = WithRuby.run(:url => 'http://www.google.co.jp/') do
|
25
25
|
%q{
|
26
|
+
require 'jcode'
|
26
27
|
require 'kconv'
|
27
28
|
require 'open-uri'
|
28
|
-
require 'rubygems'
|
29
29
|
require 'hpricot'
|
30
30
|
doc = Hpricot(open(url).read.toutf8)
|
31
31
|
return doc.inner_text
|
32
32
|
}
|
33
33
|
end
|
34
34
|
assert_match(/Google/, text)
|
35
|
-
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'raise an exception if necessary' do
|
38
|
+
assert_raise(Exception) do
|
39
|
+
WithRuby.run do
|
40
|
+
%q{
|
41
|
+
raise(Exception.new('test'))
|
42
|
+
return nil
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
36
47
|
|
37
48
|
end # context WithRuby do
|
38
49
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirobumi-with_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hirobumi Hama
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|