Class: Bundlegem::CLI::Gem
- Inherits:
-
Object
- Object
- Bundlegem::CLI::Gem
- Defined in:
- lib/bundlegem/cli/gem.rb
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(options, gem_name) ⇒ Gem
constructor
A new instance of Gem.
- #run ⇒ Object
Constructor Details
#initialize(options, gem_name) ⇒ Gem
Returns a new instance of Gem.
7 8 9 10 11 12 13 14 15 |
# File 'lib/bundlegem/cli/gem.rb', line 7 def initialize(, gem_name) = @gem_name = resolve_name(gem_name) @name = @gem_name @target = Pathname.pwd.join(gem_name) validate_ext_name if [:ext] end |
Instance Attribute Details
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
5 6 7 |
# File 'lib/bundlegem/cli/gem.rb', line 5 def gem_name @gem_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/bundlegem/cli/gem.rb', line 5 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/bundlegem/cli/gem.rb', line 5 def end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
5 6 7 |
# File 'lib/bundlegem/cli/gem.rb', line 5 def target @target end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bundlegem/cli/gem.rb', line 17 def run raise_project_with_that_name_already_exists! if File.exist?(target) underscored_name = name.tr('-', '_') namespaced_path = name.tr('-', '/') constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] unless p.empty?}.join constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/ constant_array = constant_name.split('::') git_user_name = `git config user.name`.chomp git_user_email = `git config user.email`.chomp config = { :name => name, :underscored_name => underscored_name, :namespaced_path => namespaced_path, :makefile_path => "#{underscored_name}/#{underscored_name}", :constant_name => constant_name, :constant_array => constant_array, :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name, :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email, :git_repo_url => git_user_name.empty? ? "TODO: set your git username so link to repo is automatic" : "https://github.com/#{git_user_name}/#{underscored_name}", :template => [:template], :test => [:test], :ext => [:ext], :bin => [:bin], :bundler_version => bundler_dependency_version } ensure_safe_gem_name(name, constant_array) template_src = match_template_src template_directories = dynamically_generate_template_directories templates = dynamically_generate_templates(config) puts "Creating new project folder '#{name}'\n\n" create_template_directories(template_directories, target) templates.each do |src, dst| template("#{template_src}/#{src}", target.join(dst), config) end # Bundler.ui.info "Initializing git repo in #{target}" Dir.chdir(target) { `git init`; `git add .` } # Disabled thanks to removal of thor, might not be helpful... #if options[:edit] # # Open gemspec in editor # # # thor.run("#{options["edit"]} \"#{target.join("#{name}.gemspec")}\"") #end puts "\nComplete." end |