hirobumi-with_ruby 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module WithRuby
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
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 -rrubygems'
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
- "STDOUT.puts(YAML.dump(__with_ruby))\n" +
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
 
@@ -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.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-04-27 00:00:00 -07:00
12
+ date: 2009-05-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15