Class: Ecrire::Commands::New

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#shift_argv!

Constructor Details

#initialize(options = {}, *args) ⇒ New

Returns a new instance of New.



12
13
14
15
16
17
18
19
20
# File 'lib/ecrire/commands/new.rb', line 12

def initialize(options = {}, *args)
  if args[0].nil?
    puts 'Please specify a blog name.'
    puts 'Example: ecrire new blog.domain.com'
    exit
  end
  @path = Pathname.new(Dir.pwd)
  @path += args[0]
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/ecrire/commands/new.rb', line 11

def path
  @path
end

Instance Method Details

#ask_to_overwrite!Object



37
38
39
40
41
42
43
44
# File 'lib/ecrire/commands/new.rb', line 37

def ask_to_overwrite!
  puts "You are about to overwrite #{@path} with a new theme."
  puts "Are you sure? [y/n]"
  confirm = STDIN.gets.chomp
  if confirm != 'y'
    exit
  end
end

#generate!Object



30
31
32
33
34
35
# File 'lib/ecrire/commands/new.rb', line 30

def generate!
  Dir.mkdir @path
  Dir.chdir @path
  template = File.expand_path '../../template/*', __FILE__
  FileUtils.cp_r(Dir[template], @path)
end

#run!Object



22
23
24
25
26
27
28
# File 'lib/ecrire/commands/new.rb', line 22

def run!
  if Dir.exist?(@path)
    ask_to_overwrite!
    FileUtils.rm_rf(@path)
  end
  generate!
end