Class: KStarter::Starters::Base

Inherits:
Object
  • Object
show all
Includes:
TtyHelpers
Defined in:
lib/k_starter/starters/base.rb

Overview

Generate command line for a new ruby gem project.

Direct Known Subclasses

Gem, Svelte

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TtyHelpers

#command, #config, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(project, **args) ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/k_starter/starters/base.rb', line 12

def initialize(project, **args)
  @project = project
  @code_open_delay = args[:code_open_delay] || 0
end

Instance Attribute Details

#code_open_delayObject (readonly)

Returns the value of attribute code_open_delay.



10
11
12
# File 'lib/k_starter/starters/base.rb', line 10

def code_open_delay
  @code_open_delay
end

#projectObject (readonly)

Returns the value of attribute project.



9
10
11
# File 'lib/k_starter/starters/base.rb', line 9

def project
  @project
end

Instance Method Details

#ask_destroy_existing_projectObject



47
48
49
# File 'lib/k_starter/starters/base.rb', line 47

def ask_destroy_existing_project
  question.yes?('Do you want to destroy the existing project folder')
end

#ask_exit_if_project_existsObject



51
52
53
# File 'lib/k_starter/starters/base.rb', line 51

def ask_exit_if_project_exists
  question.yes?('This project exists. Do you want to cancel new project creation?')
end

#create_kbuilderObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/k_starter/starters/base.rb', line 60

def create_kbuilder
  KManager::Cli::Commands::New.new.call(
    project_folder: project.expanded_project_path,
    builder_folder: File.join(project.expanded_project_path, '.builders'),
    description: project.description,
    user_story: project.story.user_story,
    repo_organization: project.github_organization,
    template: project.klue_template.name,
    log_level: nil,
    force: true
  )
end

#exiting(message = 'Exiting') ⇒ Object



55
56
57
58
# File 'lib/k_starter/starters/base.rb', line 55

def exiting(message = 'Exiting')
  question.warn(message)
  nil
end

#project_open_in_vscodeObject



39
40
41
42
43
44
45
# File 'lib/k_starter/starters/base.rb', line 39

def project_open_in_vscode
  sleep code_open_delay if code_open_delay.positive?

  Dir.chdir(project.expanded_project_path) do
    system('code .')
  end
end

#project_path_deleteObject



33
34
35
36
37
# File 'lib/k_starter/starters/base.rb', line 33

def project_path_delete
  return unless project_path_exist?

  FileUtils.rm_rf(project.expanded_project_path)
end

#project_path_exist?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/k_starter/starters/base.rb', line 29

def project_path_exist?
  File.exist?(project.expanded_project_path)
end

#system_in_project(script) ⇒ Object



23
24
25
26
27
# File 'lib/k_starter/starters/base.rb', line 23

def system_in_project(script)
  Dir.chdir(project.expanded_project_path) do
    system script
  end
end

#system_in_root(script) ⇒ Object



17
18
19
20
21
# File 'lib/k_starter/starters/base.rb', line 17

def system_in_root(script)
  Dir.chdir(project.expanded_root_path) do
    system script
  end
end