Class: Ecrire::Commands::New
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #ask_to_overwrite! ⇒ Object
- #generate! ⇒ Object
-
#initialize(options = {}, *args) ⇒ New
constructor
A new instance of New.
- #run! ⇒ Object
Methods inherited from Base
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( = {}, *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
#path ⇒ Object (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. '../../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 |