hirobumi-with_ruby 0.1.1

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/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = WithRuby
2
+
3
+ TODO
4
+
5
+ == Installation
6
+
7
+ sudo gem install with_ruby --no-ri --no-rdoc -s http://gems.github.com
8
+
9
+ == Usage
10
+
11
+ TODO
12
+
13
+ == License
14
+
15
+ Copyright (c) 2009 Hirobumi Hama
16
+
17
+ Permission is hereby granted, free of charge, to any person
18
+ obtaining a copy of this software and associated documentation
19
+ files (the "Software"), to deal in the Software without
20
+ restriction, including without limitation the rights to use,
21
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ copies of the Software, and to permit persons to whom the
23
+ Software is furnished to do so, subject to the following
24
+ conditions:
25
+
26
+ The above copyright notice and this permission notice shall be
27
+ included in all copies or substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
31
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
36
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/with_ruby/version'
6
+
7
+ task :default => :test
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = 'with_ruby'
11
+ s.version = WithRuby::Version.to_s
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w(README.rdoc)
14
+ s.rdoc_options = %w(--main README.rdoc)
15
+ s.summary = ""
16
+ s.author = 'Hirobumi Hama'
17
+ s.email = 'hama@yoidore.org'
18
+ s.homepage = 'http://yoidore.org'
19
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
20
+ # s.executables = ['with_ruby']
21
+
22
+ # s.add_dependency('gem_name', '~> 0.0.1')
23
+ end
24
+
25
+ Rake::GemPackageTask.new(spec) do |pkg|
26
+ pkg.gem_spec = spec
27
+ end
28
+
29
+ Rake::TestTask.new do |t|
30
+ t.libs << 'test'
31
+ t.test_files = Dir.glob('test/**/*_test.rb')
32
+ t.verbose = false
33
+ end
34
+
35
+ desc 'Generate the gemspec to serve this Gem from Github'
36
+ task :github do
37
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
38
+ File.open(file, 'w') {|f| f << spec.to_ruby }
39
+ puts "Created gemspec: #{file}"
40
+ end
@@ -0,0 +1,13 @@
1
+ module WithRuby
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 1
7
+
8
+ def self.to_s # :nodoc:
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
data/lib/with_ruby.rb ADDED
@@ -0,0 +1,41 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module WithRuby
4
+
5
+ class << self
6
+
7
+ def run(options = {})
8
+ bin = options.delete('bin') || '/usr/bin/env ruby -Ku -rrubygems'
9
+
10
+ command = yield.to_s
11
+
12
+ ret = nil
13
+ IO.popen(bin, 'r+') do |io|
14
+ io.puts(build(command, options))
15
+ ret = YAML.load(io.read)
16
+ end
17
+
18
+ ret
19
+ end
20
+
21
+ def build(command, options)
22
+ "require 'yaml'\n" +
23
+ "def __with_ruby\n" +
24
+ build_params(options) +
25
+ command +
26
+ "end\n" +
27
+ "STDOUT.puts(YAML.dump(__with_ruby))\n" +
28
+ "__END__"
29
+ end
30
+
31
+ def build_params(options)
32
+ options.map do |key, val|
33
+ "#{key} = YAML.load(%q{#{YAML.dump(val)}})"
34
+ end.join("\n")
35
+ end # def build(options)
36
+
37
+ end # class << self
38
+
39
+ end # module WithRuby
40
+
41
+ require 'with_ruby/version'
@@ -0,0 +1,10 @@
1
+ # http://sneaq.net/textmate-wtf
2
+ $:.reject! { |e| e.include? 'TextMate' }
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+
7
+ gem 'thoughtbot-shoulda', '>= 2.10.1'
8
+ require 'shoulda'
9
+
10
+ require File.dirname(__FILE__) + '/../lib/with_ruby'
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class WithRubyTest < Test::Unit::TestCase
4
+
5
+ context WithRuby do
6
+
7
+ should 'run' do
8
+ hoge = WithRuby.run(:moge => 2, :huga => 3) do
9
+ %q{
10
+ return moge * huga
11
+ }
12
+ end
13
+ assert_equal(6, hoge)
14
+ end
15
+
16
+ should 'build params' do
17
+ hoge, moge = nil
18
+ eval(WithRuby.build_params(:hoge => 1, :moge => 'two'))
19
+ assert_equal(1, hoge)
20
+ assert_equal('two', moge)
21
+ end
22
+
23
+ should 'be able to handle Hpricot' do
24
+ text = WithRuby.run(:url => 'http://www.google.co.jp/') do
25
+ %q{
26
+ require 'kconv'
27
+ require 'open-uri'
28
+ require 'rubygems'
29
+ require 'hpricot'
30
+ doc = Hpricot(open(url).read.toutf8)
31
+ return doc.inner_text
32
+ }
33
+ end
34
+ assert_match(/Google/, text)
35
+ end
36
+
37
+ end # context WithRuby do
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hirobumi-with_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Hirobumi Hama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: hama@yoidore.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - Rakefile
27
+ - lib/with_ruby
28
+ - lib/with_ruby/version.rb
29
+ - lib/with_ruby.rb
30
+ - test/test_helper.rb
31
+ - test/unit
32
+ - test/unit/with_ruby_test.rb
33
+ has_rdoc: true
34
+ homepage: http://yoidore.org
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --main
38
+ - README.rdoc
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.2.0
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: ""
60
+ test_files: []
61
+