module Ronin::Gen::Actions

Action methods for the {Generator} class.

@since 1.2.0

@api semipublic

Constants

BOLD

ANSI Bold code

CLEAR

ANSI Clear code

GREEN

ANSI Green code

Protected Instance Methods

chmod(mode,paths) click to toggle source

Changes the permissions of a files or directories.

@param [String, Integer] mode

The new permissions for the files or directories.

@param [Array<String>] paths

The path to the files or directories.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#chmod-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 102
def chmod(mode,paths)
  print_command 'chmod', mode.to_s(8), *paths

  super(mode,paths)
end
chmod_R(mode,paths) click to toggle source

Changes the permissions of files/directories, recursively.

@param [String, Integer] mode

The new permissions for the files or directories.

@param [Array<String>] paths

The path to the files or directories.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#chmod_R-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 121
def chmod_R(mode,paths)
  print_command 'chmod -R', mode.to_s(8)

  super(mode,paths)
end
chown(user,group,paths) click to toggle source

Changes ownership of files or directories.

@param [String, nil] user

The new owner of the files or directories.

@param [String, nil] group

The new group for the files or directories.

@param [Array<String>] paths

The path to the files or directories.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#chown-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 143
def chown(user,group,paths)
  print_command 'chown', "#{user}:#{group}", *paths

  super(user,group,paths)
end
chown_R(user,group,paths) click to toggle source

Changes ownership of files/directories, recursively.

@param [String, nil] user

The new owner of the files or directories.

@param [String, nil] group

The new group for the files or directories.

@param [Array<String>] paths

The path to the files or directories.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#chown_R-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 165
def chown_R(user,group,paths)
  print_command 'chown -R', "#{user}:#{group}", *paths

  super(user,group,paths)
end
cp(file,destination=file) click to toggle source

Copies a data file.

@param [String] file

The relative path to the data file.

@param [String] destination

The destination to copy the data file to.

@since 0.2.0

@see rubydoc.info/stdlib/fileutils/FileUtils#cp-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 184
def cp(file,destination=file)
  print_command 'cp', destination

  super(data_file(file),destination)
end
cp_r(directory,destination=directory) click to toggle source

Copies the contents of all data directories.

@param [String] directory

The data directories to copy from.

@param [String, nil] destination

The optional destination directory to copy the files to.

@since 1.0.0

@see rubydoc.info/stdlib/fileutils/FileUtils#cp_r-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 203
def cp_r(directory,destination=directory)
  print_command 'cp -r', destination

  data_dirs(directory) do |dir|
    super(dir,destination)
  end
end
install(src,dest,options={}) click to toggle source

Installs a file.

@param [String] src

The file to install.

@param [String] dest

The destination path for the file.

@param [Hash] options

Additional options.

@option options [String, Integer] :mode

The permissions of the installed file.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#install-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 230
def install(src,dest,options={})
  options = {:mode => options[:mode]} # only pass in :mode

  print_command 'install', src, dest

  super(data_file(src),dest,options)
end
ln(src,dest) click to toggle source

Creates a hard link.

@param [String] src

The path file/directory for the hard link.

@param [String] dest

The destination file/directory of the hard link.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#ln-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 251
def ln(src,dest)
  print_command 'ln', src, dest

  super(src,dest)
end
ln_s(src,dest) click to toggle source

Creates a symbolic link.

@param [String] src

The path file/directory for the symbolic link.

@param [String] dest

The destination file/directory of the symbolic link.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#ln_s-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 270
def ln_s(src,dest)
  print_command 'ln -s', src, dest

  super(src,dest)
end
ln_sf(src,dest) click to toggle source

Forcibly creates a symbolic link.

@param [String] src

The path file/directory for the symbolic link.

@param [String] dest

The destination file/directory of the symbolic link.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#ln_sf-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 289
def ln_sf(src,dest)
  print_command 'ln -sf', src, dest

  super(src,dest)
end
mkdir(dir) click to toggle source

Creates an empty directory.

@param [String] dir

The relative path of the directory to create.

@example

mkdir 'sub/dir'

@since 0.2.0

@see rubydoc.info/stdlib/fileutils/FileUtils#mkdir-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 308
def mkdir(dir)
  print_command 'mkdir', dir

  super(dir)
end
mkdir_p(dir) click to toggle source

Creates an empty directory.

@param [String] dir

The relative path of the directory to create.

@example

mkdir 'sub/dir'

@since 0.2.0

@see rubydoc.info/stdlib/fileutils/FileUtils#mkdir_p-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 327
def mkdir_p(dir)
  print_command 'mkdir', dir

  super(dir)
end
mv(src,dest) click to toggle source

Moves a file or directory.

@param [String] src

The path to the file or directory.

@param [String] dest

The new path to move the file or directory to.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#mv-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 346
def mv(src,dest)
  print_command 'mv', src, dest

  super(src,dest)
end
print_command(command,*arguments) click to toggle source

Prints a file action.

@param [String] command

The command/options that represents the file action.

@param [Array<String>] arguments

Additional arguments related to the file action.

@since 1.2.0

rm(paths,options={}) click to toggle source

Removes one or more files.

@param [Array<String>] paths

The paths of the files and directories to remove.

@param [Hash] options

Additional options.

@option options [Boolean] :force

Specifies whether to forcible remove the files.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#rm-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 368
def rm(paths,options={})
  options = {:force => options[:force]} # only pass in :force

  print_command 'rm', *paths

  super(paths,options)
end
rm_r(paths,options={}) click to toggle source

Recursively removes files and directories.

@param [Array<String>] paths

The paths of the files and directories to remove.

@param [Hash] options

Additional options.

@option options [Boolean] :force

Specifies whether to forcible remove the files.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#rm_r-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 392
def rm_r(paths,options={})
  options = {:force => options[:force]} # only pass in :force

  print_command 'rm -r', *paths

  super(paths,options)
end
rm_rf(paths) click to toggle source

Forcibly removes files and directories, recursively.

@param [Array<String>] paths

The paths of the files and directories to remove.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#rm_rf-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 410
def rm_rf(paths)
  print_command 'rm -rf', *paths

  super(paths)
end
rmdir(dirs) click to toggle source

Removes one or more directories.

@param [Array<String>] dirs

The paths of the directories.

@since 1.1.0

@see rubydoc.info/stdlib/fileutils/FileUtils#rmdir-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 426
def rmdir(dirs)
  print_command 'rmdir', *dirs

  super(dirs)
end
run(command,*arguments) click to toggle source

Runs a command.

@param [String] command

The command or program to run.

@param [Array<String>] arguments

Additional arguments to run the program with.

@since 1.1.0

# File lib/ronin/gen/actions.rb, line 83
def run(command,*arguments)
  print_command command, *arguments

  system(command,*arguments)
end
template(template_path,destination=nil) click to toggle source

Renders the ERB template and saves the result.

@param [String] template_path

The relative path to the template.

@param [String, nil] destination

The destination to write the result of the rendered template to.

@return [nil, String]

If destination is `nil`, the result of the rendered template
will be returned.

@example

template 'Rakefile.erb', 'Rakefile'

@example

template '_helpers.erb'

@since 0.2.0

# File lib/ronin/gen/actions.rb, line 490
def template(template_path,destination=nil)
  if destination
    print_command 'erb', destination

    File.open(destination,'w') do |file|
      file.write(erb_file(template_path))
    end
  else
    erb_file(template_path).chomp
  end
end
touch(path) click to toggle source

Touches a file.

@param [String] path

The relative path to the file to touch.

@example

touch 'TODO.txt'

@since 0.2.0

@see rubydoc.info/stdlib/fileutils/FileUtils#touch-instance_method

Calls superclass method
# File lib/ronin/gen/actions.rb, line 445
def touch(path)
  print_command 'touch', path

  return super(path)
end
write(path,&block) click to toggle source

Opens a file for writing.

@param [String] path

The path of the file to write to.

@yield [file]

The given block will be passed the newly opened file.

@yieldparam [File]

The new file file, opened for writing.

@since 1.1.0

# File lib/ronin/gen/actions.rb, line 465
def write(path,&block)
  File.open(path,'wb',&block)
end