Skip to content
Browse files

Merge pull request #41 from wwood/wrappers

Add --with-wrapper option to template wrapper biogems
  • Loading branch information...
2 parents 42e41ff + 15c6cc7 commit 01df76550b9597151b5fe452d51551c0362dbe23 @pjotrp pjotrp committed Jan 4, 2013
Showing with 43 additions and 4 deletions.
  1. +1 −0 lib/bio-gem/mod/jeweler.rb
  2. +4 −0 lib/bio-gem/mod/jeweler/options.rb
  3. +17 −1 lib/bio-gem/templates/lib/plugin.rb
  4. +21 −3 test/test_bio-gem.rb
View
1 lib/bio-gem/mod/jeweler.rb
@@ -31,6 +31,7 @@ def initialize(options = {})
development_dependencies << ["activesupport", ">= 3.0.7"]
development_dependencies << ["sqlite3", ">= 1.3.3"]
end
+ development_dependencies << ['systemu', '>=2.5.2'] if options[:wrapper]
end
alias original_project_name project_name
View
4 lib/bio-gem/mod/jeweler/options.rb
@@ -62,6 +62,10 @@ def initialize(args)
self[:biogem_db] = true
end
+ o.on('--with-wrapper', 'setup the biogem to be a wrapper around a command line application') do
+ self[:wrapper] = true
+ end
+
o.separator ""
o.separator "These options are for Jeweler"
View
18 lib/bio-gem/templates/lib/plugin.rb
@@ -1,3 +1,19 @@
-module <%= constant_name %>
+<% if options[:wrapper] %>require 'systemu'
+<% end %>
+module <%= constant_name %>
+<% if options[:wrapper] %>
+ class Wrapper
+ def run
+ command = "some_application arguments"
+ status, stdout, stderr = systemu command, 0 => 'dummy stdin'
+ if status.exitstatus != 0
+ $stderr.puts "Failed to run wrapping command correctly, as non-zero exit status "+
+ "#{status.exitstatus} detected. Command run was `#{command}'"
+ else
+ # All good. Now to something useful with the stdout..
+ end
+ end
+ end
+<% end %>
end
View
24 test/test_bio-gem.rb
@@ -5,6 +5,12 @@
class TestBiorubyGem < Test::Unit::TestCase
TEST_DIR = 'test/bioruby-biogem-test'
+ def basic_generated_files(project_name)
+ %W(Gemfile lib lib/bio-#{project_name}.rb LICENSE.txt Rakefile README.rdoc test test/helper.rb test/test_bio-#{project_name}.rb).map do |file_name_to_test|
+ File.join("bioruby-#{project_name}",file_name_to_test)
+ end
+ end
+
def setup
# check and create test directory
FileUtils.rm_rf(TEST_DIR) if Dir.exist?(TEST_DIR)
@@ -21,11 +27,23 @@ def test_create_basic_project
project_name = "biogem-test"
Dir.chdir(TEST_DIR) do
application_exit = Bio::Gem::Generator::Application.run!("--no-create-repo", "--user-name=\"fake_name\"", "--user-email=\"fake_email\"", "--github-username=\"fake_github_user\"","#{project_name}")
- files_tested = %W(Gemfile lib lib/bio-#{project_name}.rb LICENSE.txt Rakefile README.rdoc test test/helper.rb test/test_bio-#{project_name}.rb).map do |file_name_to_test|
- File.exist?(File.join("bioruby-#{project_name}",file_name_to_test))
+ basic_generated_files(project_name).each do |path|
+ assert File.exist?(path), path
end
- assert_equal [true, true, true, true, true, true, true, true, true], files_tested
end
end
+
+ def test_create_wrapper_project
+ project_name = "biogem-test2"
+ Dir.chdir(TEST_DIR) do
+ application_exit = Bio::Gem::Generator::Application.run!('--with-wrapper',"--no-create-repo", "--user-name=\"fake_name\"", "--user-email=\"fake_email\"", "--github-username=\"fake_github_user\"","#{project_name}")
+ basic_generated_files(project_name).each do |path|
+ assert File.exist?(path), path
+ end
+ assert File.read(File.join("bioruby-#{project_name}",'lib',"bio-#{project_name}","#{project_name}.rb")).match(/require 'systemu'/)
+ assert File.read(File.join("bioruby-#{project_name}",'lib',"bio-#{project_name}","#{project_name}.rb")).match(/systemu command/)
+ assert File.read(File.join("bioruby-#{project_name}",'Gemfile')).match(/gem "systemu"/)
+ end
+ end
end

0 comments on commit 01df765

Please sign in to comment.
Something went wrong with that request. Please try again.