Class: ThorTemplate::Generator
- Inherits:
-
Object
- Object
- ThorTemplate::Generator
- Defined in:
- lib/thor_template/generator.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #copy ⇒ Object
- #git ⇒ Object
-
#initialize(options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #rename ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
8 9 10 11 12 |
# File 'lib/thor_template/generator.rb', line 8 def initialize(={}) @options = Dir.chdir([:cwd]) if [:cwd] @name = [:name] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/thor_template/generator.rb', line 7 def @options end |
Instance Method Details
#copy ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/thor_template/generator.rb', line 21 def copy project_root = @name source_root = File.("../../starter_project", __FILE__) paths = Dir.glob("#{source_root}/**/{*,.*}"). select {|p| File.file?(p) } paths.each do |src| dest = src.gsub(%r{.*starter_project/},'') dest = "#{project_root}/#{dest}" if File.exist?(dest) and ![:force] puts "already exists: #{dest}".colorize(:yellow) unless [:quiet] else puts "creating: #{dest}".colorize(:green) unless [:quiet] dirname = File.dirname(dest) FileUtils.mkdir_p(dirname) unless File.exist?(dirname) FileUtils.cp(src, dest) end end end |
#git ⇒ Object
45 46 47 48 49 |
# File 'lib/thor_template/generator.rb', line 45 def git system("cd #{@name} && git init") system("cd #{@name} && git add .") system("cd #{@name} && git commit -m 'first commit'") end |
#rename ⇒ Object
41 42 43 |
# File 'lib/thor_template/generator.rb', line 41 def rename Renamer.new(@name).rename! end |
#run ⇒ Object
14 15 16 17 18 19 |
# File 'lib/thor_template/generator.rb', line 14 def run copy rename git puts "Created #{@name} project!" end |