Class: Ronin::CLI::Commands::New::Project Private

Inherits:
Ronin::CLI::Command show all
Includes:
Core::CLI::Generator
Defined in:
lib/ronin/cli/commands/new/project.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Creates new Ruby project directory.

Usage

ronin new project [options] DIR

Options

    --git                        Initializes a git repo
    --ruby-version VERSION       The desired ruby version for the project
    --rakefile                   Creates a Rakefile
-D, --dockerfile                 Adds a Dockerfile to the new project
-h, --help                       Print help information

Arguments

PATH                             The directory to create

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#run(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin new project command.

Parameters:

  • path (String)

    The path to the new project directory to create.

Since:

  • 2.0.0



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ronin/cli/commands/new/project.rb', line 81

def run(path)
  @project_name = File.basename(path)
  @ruby_version = options[:ruby_version]

  mkdir path
  mkdir File.join(path,'lib')

  erb '.ruby-version.erb', File.join(path,'.ruby-version')
  erb 'Gemfile.erb', File.join(path,'Gemfile')

  if options[:rakefile]
    cp 'Rakefile', path
  end

  if options[:dockerfile]
    erb 'Dockerfile.erb', File.join(path,'Dockerfile')
  end

  project_file = File.join(path,"#{@project_name}.rb")

  erb 'project.rb.erb', project_file
  chmod '+x',           project_file

  if options[:git]
    cp '.gitignore', path

    Dir.chdir(path) do
      sh 'git', 'init', '-q', '-b', 'main'
      sh 'git', 'add', '.'
      sh 'git', 'commit', '-q', '-m', 'Initial commit.'
    end
  end
end