Class: Gemgen::Generator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Gemgen::Generator
- Includes:
- Thor::Actions
- Defined in:
- lib/gemgen/generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_test_dependencies ⇒ Object
- #adding_test_tasks ⇒ Object
- #create_test_file ⇒ Object
- #debug_gem_to_Gemfile ⇒ Object
- #fix_already_initialized_constant_version_warning ⇒ Object
- #run_bundle_gem ⇒ Object
Class Method Details
.source_root ⇒ Object
12 13 14 |
# File 'lib/gemgen/generator.rb', line 12 def self.source_root File.(File.dirname(__FILE__) +'/templates') end |
Instance Method Details
#add_test_dependencies ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gemgen/generator.rb', line 29 def add_test_dependencies inside gem_name do insert_into_file "#{gem_name}.gemspec", :after => /gem.version.*\n/ do str = <<EOF # gem.add_dependency "put dependency here" gem.add_development_dependency 'rake' gem.add_development_dependency "bundler", "~> 1.0" gem.add_development_dependency 'minitest' EOF end end bundle commit('Add testing gem dependencies') end |
#adding_test_tasks ⇒ Object
44 45 46 47 48 |
# File 'lib/gemgen/generator.rb', line 44 def adding_test_tasks remove_file("#{gem_name}/Rakefile") template('Rakefile.tt', "#{gem_name}/Rakefile") commit "Add test tasks" end |
#create_test_file ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/gemgen/generator.rb', line 50 def create_test_file test = [:test_type] == "spec" ? :spec : :test test_path = "#{gem_name}/#{test}/" helper_file = "#{test}_helper.rb" create_file test_path + helper_file do unit_str = <<EOF $:.unshift File.expand_path('..', __FILE__) $:.unshift File.expand_path('../../lib', __FILE__) require 'minitest/unit' require 'minitest/autorun' EOF spec_str = <<EOF $:.unshift File.expand_path('..', __FILE__) $:.unshift File.expand_path('../../lib', __FILE__) require '#{gem_name}' require 'minitest/spec' require 'minitest/autorun' module SpecHelper end EOF test == :spec ? spec_str : unit_str end create_file test_path + "#{gem_name}_#{test}.rb" do unit_str = <<EOF require '#{File.basename(helper_file, ".rb")}' module #{module_name} class #{module_name}Test < MiniTest::Unit::TestCase def test_truth assert true end end end EOF spec_str = <<EOF require File.expand_path('../spec_helper', __FILE__) require File.expand_path(File.dirname(__FILE__) + '/spec_helper') include SpecHelper describe #{module_name} do before do end it "should test truth" do true.must_equal true end end EOF test == :spec ? spec_str : unit_str end commit("Create test scaffold file") end |
#debug_gem_to_Gemfile ⇒ Object
105 106 107 108 109 110 |
# File 'lib/gemgen/generator.rb', line 105 def debug_gem_to_Gemfile remove_file("#{gem_name}/Gemfile") template('Gemfile.tt', "#{gem_name}/Gemfile") bundle commit "Add debug gem to Gemfile" end |
#fix_already_initialized_constant_version_warning ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/gemgen/generator.rb', line 21 def fix_already_initialized_constant_version_warning inside gem_name do sub_str = "$:.unshift File.expand_path('../lib', __FILE__)\nrequire '#{gem_name}/version'" gsub_file "#{gem_name}.gemspec", /^.*version', __FILE__.*$/, sub_str end commit "Fix already initialized constant VERSION warning" end |
#run_bundle_gem ⇒ Object
16 17 18 19 |
# File 'lib/gemgen/generator.rb', line 16 def run_bundle_gem run "bundle gem #{gem_name}", :verbose => true commit "$> bundle gem #{gem_name}" end |