Class: Yap::Cli::Commands::Generate::Addon
- Inherits:
-
Object
- Object
- Yap::Cli::Commands::Generate::Addon
- Defined in:
- lib/yap/cli/commands/generate/addon.rb
Instance Attribute Summary collapse
-
#addon_name ⇒ Object
Returns the value of attribute addon_name.
-
#use_git ⇒ Object
Returns the value of attribute use_git.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #doing(text, &block) ⇒ Object
-
#initialize(addon_name) ⇒ Addon
constructor
A new instance of Addon.
- #process ⇒ Object
Constructor Details
#initialize(addon_name) ⇒ Addon
Returns a new instance of Addon.
10 11 12 13 14 |
# File 'lib/yap/cli/commands/generate/addon.rb', line 10 def initialize(addon_name) @addon_name = addon_name.gsub(/[^\w\-_]+/, '-').downcase @version = '0.1.0' @use_git = true end |
Instance Attribute Details
#addon_name ⇒ Object
Returns the value of attribute addon_name.
8 9 10 |
# File 'lib/yap/cli/commands/generate/addon.rb', line 8 def addon_name @addon_name end |
#use_git ⇒ Object
Returns the value of attribute use_git.
8 9 10 |
# File 'lib/yap/cli/commands/generate/addon.rb', line 8 def use_git @use_git end |
#version ⇒ Object
Returns the value of attribute version.
8 9 10 |
# File 'lib/yap/cli/commands/generate/addon.rb', line 8 def version @version end |
Instance Method Details
#doing(text, &block) ⇒ Object
16 17 18 19 20 |
# File 'lib/yap/cli/commands/generate/addon.rb', line 16 def doing(text, &block) print "#{text}" block.call puts " #{Term::ANSIColor.green('done')}" end |
#process ⇒ Object
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 |
# File 'lib/yap/cli/commands/generate/addon.rb', line 22 def process puts "Creating addon #{Term::ANSIColor.yellow(addon_name)} in #{addon_dir}/" puts mkdir addon_dir Dir.chdir addon_dir do mkdir lib_path write_file 'Gemfile', gemfile_contents write_file gemspec_name, gemspec_contents write_file 'LICENSE.txt', license_contents write_file 'Rakefile', rakefile_contents write_file 'README.md', readme_contents write_file addonrb_path, addonrb_contents mkdir lib_addon_path write_file version_path, version_contents puts if use_git && `which git` && $?.exitstatus == 0 write_file '.gitignore', gitignore_contents doing "git init . && git add . && git commit -m 'initial commit of #{addon_name}'" do `git init . && git add . && git commit -m 'initial commit of #{addon_name} addon for yap'` end else puts "Git initialization #{Term::ANSIColor.cyan('skipped')}" end end puts puts "Yap addon generated! A few helpful things to note:" puts puts <<-TEXT.gsub(/^\s*\|/, '') | * The #{Term::ANSIColor.yellow(addon_name)} addon has been generated in #{addon_dir}/ | * It is a standard rubygem, has its own gemspec, and is named #{Term::ANSIColor.yellow(gem_safe_addon_name)} | * Yap loads the #{Term::ANSIColor.yellow(constant_name)}, found in #{addonrb_path} (start there) | * Share your addon with others by building a gem and pushing it to rubygems | |For more information see https://github.com/zdennis/yap-shell/wiki/Addons | |Now, to get started: | | cd #{gem_safe_addon_name} TEXT puts end |