Class: Textigniter::Init
- Inherits:
-
Object
- Object
- Textigniter::Init
- Defined in:
- lib/textigniter/init.rb
Overview
The Init class creates a new textigniter environment by duplicating a skeleton directory stored in the gem. The class will either duplicate this directory into the current working directory or a directory of choice by arguments passed on the command line.
Instance Method Summary collapse
-
#env_check ⇒ Object
check for existing environment.
-
#initialize(args) ⇒ Init
constructor
A new instance of Init.
-
#skeleton ⇒ Object
Duplicate the skeleton into the current working directory/passed directory.
Constructor Details
#initialize(args) ⇒ Init
Returns a new instance of Init.
7 8 9 10 |
# File 'lib/textigniter/init.rb', line 7 def initialize(args) # Sends message to cli STDOUT.puts "Initializing a new textigniter environment".yellow_on_black end |
Instance Method Details
#env_check ⇒ Object
check for existing environment
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/textigniter/init.rb', line 13 def env_check unless File.directory? $base_path # Make the directory FileUtils.mkdir($base_path) # Change into the dir FileUtils.cd($base_path) # return true return true else unless File.directory? $twd return true else return false end end end |
#skeleton ⇒ Object
Duplicate the skeleton into the current working directory/passed directory
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/textigniter/init.rb', line 31 def skeleton # Get the current working directory path cwd = "#{Dir::pwd}/" # Get the skeleton directory path swd = "#{$gem_path}/skeleton/" # Run a check for existing environment if File.directory?($twd) # Output error and resolution message STDOUT.puts "[FAIL]".red_on_black + " Existing textigniter environment".yellow_on_black STDOUT.puts "\r\nHint: If you need to start over, use ".white_on_black + "textigniter scrub".bold.white_on_black else # Build list of files files = Dir.glob(swd + '*', File::FNM_DOTMATCH) # Clean up the list, removes .. & . # If someone has a better solution for this, please let me know files.delete(swd + '.') files.delete(swd + '..') # Use fileutils to build the directory FileUtils.cp_r files, cwd # Output success message STDOUT.puts "Textigniter environment initiliazed ".yellow_on_black + "[OK]".green_on_black end end |