Skip to content

Instantly share code, notes, and snippets.

@tamouse
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamouse/9439598 to your computer and use it in GitHub Desktop.
Save tamouse/9439598 to your computer and use it in GitHub Desktop.
Using thor to generate a new ruby project.
$ bundle gem GEMNAME -b -t
.gitignore
.pryrc
.rspec
CHANGELOG.txt
CONTRIBUTING.md
Gemfile
gitignore
Guardfile
Procfile
Rakefile
README.md
bin/
executable
doc/
lib/
library.rb
library/
version.rb
LICENSE.txt
log/
spec/
spec_helper.rb
lib/
library_spec.rb
library/
support/
tmp/
guard :bundler do
watch('Gemfile')
# Uncomment next line if your Gemfile contains the `gemspec' command.
# watch(/^.+\.gemspec/)
end
guard :rspec, :cmd => "bundle exec rspec" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
# -*- ruby -*-
require 'thor'
class NewRubyProject < Thor::Group
include Thor::Actions
argument :name
def self.source_root
File.expand_path("../new_project_template",__FILE__)
end
def name_components
@_name_components ||= name.scan(/[[:alnum:]]+/)
end
def snake_name
@_snake_name ||= name_components.map(&:downcase).join("_")
end
def camel_name
@_camel_name ||= name_components.map(&:capitalize).join("")
end
def copy_files
%w[README.md CHANGELOG.txt CONTRIBUTING.md LICENSE.txt Gemfile Guardfile Rakefile Procfile].each do |f|
template f, "#{snake_name}/#{f}"
end
end
def copy_dot_files
%w[gitignore pryrc rspec].each do |f|
template f, "#{snake_name}/.#{f}"
end
end
def other_file
template "bin/executable", "#{snake_name}/bin/#{snake_name}"
template "lib/library.rb", "#{snake_name}/lib/#{snake_name}.rb"
template "lib/library/version.rb", "#{snake_name}/lib/#{snake_name}/version.rb"
template "spec/spec_helper.rb", "#{snake_name}/spec/spec_helper.rb"
template "spec/lib/library_spec.rb", "#{snake_name}/spec/lib/#{snake_name}_spec.rb"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment