Class: Rubee::CLI::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/rubee/cli/project.rb

Class Method Summary collapse

Class Method Details

.call(command, argv) ⇒ Object



5
6
7
# File 'lib/rubee/cli/project.rb', line 5

def call(command, argv)
  send(command, argv)
end

.project(argv) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubee/cli/project.rb', line 9

def project(argv)
  project_name = argv[1]

  if project_name.nil?
    color_puts('Please indicate project name.', color: :red)
    exit(1)
  end

  if project_name == 'rubee'
    color_puts("Error: Project 'rubee' is reserved", color: :red)
    exit(1)
  end
  source_dir = File.join(Rubee::ROOT_PATH, '/lib')
  target_dir = File.expand_path("./#{project_name}", Dir.pwd)

  if Dir.exist?(target_dir)
    color_puts("Error: Project #{project_name} already exists!", color: :red)
    exit(1)
  end
  # Create target directory
  FileUtils.mkdir_p(target_dir)
  # Define blacklist
  blacklist_files = %w[rubee.rb print_colors.rb version.rb config.ru test_helper.rb Gemfile.lock test.yml test.db
                       development.db production.db users_controller.rb users_controller.rb]
  blacklist_dirs = %w[rubee tests .git .github .idea node_modules db inits]
  # Copy files, excluding blacklisted ones
  copy_project_files(source_dir, target_dir, blacklist_files, blacklist_dirs)
  # create tests dir and copy test_helper.rb and user_model_test.rb
  setup_test_structure(target_dir, source_dir)
  # create db dir
  setup_db_structure(target_dir, source_dir)
  # create inits dir
  FileUtils.mkdir_p("#{target_dir}/inits")
  # create a gemfile context
  setup_gemfile(target_dir)
  color_puts("Project #{project_name} created successfully at #{target_dir}", color: :green)
end