class Textigniter::Init

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.

Public Class Methods

new(args) click to toggle source
# 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

Public Instance Methods

env_check() click to toggle source

check for existing environment

# 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() click to toggle source

Duplicate the skeleton into the current working directory/passed directory

# 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