Class: Nesta::Commands::New

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/nesta/commands.rb

Instance Method Summary collapse

Methods included from Command

#copy_template, #copy_templates, #fail, #run_process, #template_root, #update_config_yaml

Constructor Details

#initialize(*args) ⇒ New

Returns a new instance of New



85
86
87
88
89
90
91
92
93
94
# File 'lib/nesta/commands.rb', line 85

def initialize(*args)
  path = args.shift
  options = args.shift || {}
  path.nil? && (raise UsageError.new('path not specified'))
  if File.exist?(path)
    raise RuntimeError.new("#{path} already exists") 
  end
  @path = path
  @options = options
end

Instance Method Details

#create_repositoryObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/nesta/commands.rb', line 106

def create_repository
  FileUtils.cd(@path) do
    File.open('.gitignore', 'w') do |file|
      file.puts %w[._* .*.swp .bundle .DS_Store .sass-cache].join("\n")
    end
    run_process('git', 'init')
    run_process('git', 'add', '.')
    run_process('git', 'commit', '-m', 'Initial commit')
  end
end

#executeObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/nesta/commands.rb', line 117

def execute
  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
  copy_templates(templates)
  create_repository if @options['git']
end

#have_rake_tasks?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/nesta/commands.rb', line 102

def have_rake_tasks?
  @options['vlad']
end

#make_directoriesObject



96
97
98
99
100
# File 'lib/nesta/commands.rb', line 96

def make_directories
  %w[content/attachments content/pages].each do |dir|
    FileUtils.mkdir_p(File.join(@path, dir))
  end
end