Created
November 6, 2011 13:59
-
-
Save niku/1342912 to your computer and use it in GitHub Desktop.
my create gem script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def gem_name | |
ARGV[0].chomp("/") | |
end | |
def constant_name | |
constant_name = gem_name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join | |
constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/ | |
constant_name | |
end | |
def constant_array | |
constant_name.split('::') | |
end | |
def rvmrc | |
"rvm 1.9.3\n" | |
end | |
def gem_name_spec | |
str = "" | |
str << "require \"spec_helper\"\n" | |
str << "\n" | |
constant_array[0..-2].each_with_index do |c,i| | |
str << " " * i | |
str << "module " << c << "\n" | |
end | |
str << " " * (constant_array.size - 1) << "describe " << constant_array.last << " do\n" | |
str << " " * constant_array.size << "it{ fail \"not implement yet.\" }\n" | |
(constant_array.size - 1).downto(0) do |i| | |
str << " " * i << "end\n" | |
end | |
str | |
end | |
def gemfile_for_rspec | |
str = "" | |
str << "\n" | |
str << "gem \"rake\"\n" | |
str << "gem \"rspec\"\n" | |
str | |
end | |
def rakefile_for_rspec | |
str = "" | |
str << "\n" | |
str << "require \"rspec/core/rake_task\"\n" | |
str << "RSpec::Core::RakeTask.new(:spec)\n" | |
str << "task :default => :spec\n" | |
str | |
end | |
def gemfile_for_guard | |
str = "" | |
str << "\n" | |
str << "gem \"guard\", :require => false\n" | |
str << "gem \"guard-rspec\", :require => false\n" | |
str << "gem \"ruby_gntp\", :require => false\n" | |
str | |
end | |
def travis | |
"rvm: 1.9.3\n" | |
end | |
system "bundle gem #{gem_name}" # create base | |
Dir.chdir gem_name do | |
# add rvm | |
## to rvmrc | |
File.write(".rvmrc", rvmrc) | |
# add rspec | |
## to Gemfile | |
File.open("Gemfile", "a"){ |f| f << gemfile_for_rspec } | |
## to Rakefile | |
File.open("Rakefile", "a"){ |f| f << rakefile_for_rspec } | |
## init | |
system "bundle exec rspec --init" | |
## to spec directory | |
File.write("spec/#{gem_name}_spec.rb", gem_name_spec) | |
## add 'require "gem_name"' to spec_helper | |
File.write("spec/spec_helper.rb", "require \"#{gem_name}\"\n" << File.read("spec/spec_helper.rb")) | |
# add guard | |
## to Gemfile | |
File.open("Gemfile", "a"){ |f| f << gemfile_for_guard } | |
## init | |
system "bundle exec guard init rspec" | |
# add travis | |
## to travis.yml | |
File.write(".travis.yml", travis) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment