Class: Nesta::Commands::New
- Inherits:
-
Object
- Object
- Nesta::Commands::New
- Defined in:
- lib/nesta/commands/new.rb
Instance Method Summary collapse
- #create_repository(process) ⇒ Object
- #execute(process) ⇒ Object
- #have_rake_tasks? ⇒ Boolean
-
#initialize(*args) ⇒ New
constructor
A new instance of New.
- #make_directories ⇒ Object
Constructor Details
#initialize(*args) ⇒ New
Returns a new instance of New.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/nesta/commands/new.rb', line 4 def initialize(*args) path = args.shift = args.shift || {} path.nil? && (raise UsageError.new('path not specified')) if File.exist?(path) raise RuntimeError.new("#{path} already exists") end @path = path @options = end |
Instance Method Details
#create_repository(process) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nesta/commands/new.rb', line 25 def create_repository(process) FileUtils.cd(@path) do File.open('.gitignore', 'w') do |file| lines = %w[._* .*.swp .bundle .DS_Store .sass-cache dist] file.puts lines.join("\n") end process.run('git', 'init') process.run('git', 'add', '.') process.run('git', 'commit', '-m', 'Initial commit') end end |
#execute(process) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nesta/commands/new.rb', line 37 def execute(process) make_directories templates = { 'config.ru' => "#{@path}/config.ru", 'config/config.yml' => "#{@path}/config/config.yml", 'index.haml' => "#{@path}/content/pages/index.haml", 'Gemfile' => "#{@path}/Gemfile" } templates['Rakefile'] = "#{@path}/Rakefile" if have_rake_tasks? if @options['vlad'] templates['config/deploy.rb'] = "#{@path}/config/deploy.rb" end templates.each do |src, dest| Nesta::Commands::Template.new(src).copy_to(dest, binding) end create_repository(process) if @options['git'] end |
#have_rake_tasks? ⇒ Boolean
21 22 23 |
# File 'lib/nesta/commands/new.rb', line 21 def have_rake_tasks? @options['vlad'] end |
#make_directories ⇒ Object
15 16 17 18 19 |
# File 'lib/nesta/commands/new.rb', line 15 def make_directories %w[content/attachments content/pages].each do |dir| FileUtils.mkdir_p(File.join(@path, dir)) end end |