Module: Aladdin::Commands::New

Extended by:
New
Included in:
New
Defined in:
lib/aladdin/commands/new.rb

Overview

Examples:

$> aladdin new path/to/lesson/root

Constant Summary collapse

FILES =

Array of skeleton files to be copied over.

['images', Spirit::MANIFEST, Spirit::INDEX]
DOT_FILES =

Array of dot files to be copied over and renamed.

%w(gitignore)
COPY_FLAGS =

Flags for FileUtils.cp_r

{verbose: true}

Instance Method Summary collapse

Instance Method Details

#copy_files(dest, flags = {}) ⇒ Void

Copies skeleton files to given destination.

Parameters:

  • dest (String)

    destination path

  • flags (Hash) (defaults to: {})

    options for FileUtils.cp_r

Returns:

  • (Void)


27
28
29
30
31
32
33
34
# File 'lib/aladdin/commands/new.rb', line 27

def copy_files(dest, flags={})
  flags = COPY_FLAGS.merge flags
  paths = FILES.map { |file| path_to file }
  FileUtils.cp_r paths, dest, flags
  DOT_FILES.each do |file|
    FileUtils.cp_r path_to(file), File.join(dest, '.' + file), flags
  end
end

#parse!(argv) ⇒ Void

Parses the command line arguments.

Parameters:

  • argv (Array)

    command line arguments

Returns:

  • (Void)


46
47
48
49
50
51
# File 'lib/aladdin/commands/new.rb', line 46

def parse!(argv)
  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: aladdin new [options] [LESSON_PATH]"
  end
  opt_parser.parse! argv
end

#path_to(file) ⇒ String

Prefixes file with the skeleton directory.

Parameters:

  • file (String)

    name of file to resolve

Returns:

  • (String)

    path



39
40
41
# File 'lib/aladdin/commands/new.rb', line 39

def path_to(file)
  File.expand_path file, Aladdin::PATHS.skeleton
end