Class: Nesta::Commands::New

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

Instance Method Summary collapse

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
  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_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

Returns:

  • (Boolean)


21
22
23
# File 'lib/nesta/commands/new.rb', line 21

def have_rake_tasks?
  @options['vlad']
end

#make_directoriesObject



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