Class: KStarter::Questions::BaseQuestion

Inherits:
Object
  • Object
show all
Includes:
TtyHelpers
Defined in:
lib/k_starter/questions/base_question.rb

Overview

Ask code generations for a new projects.

Direct Known Subclasses

BaseGem, Rails, 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(**args) ⇒ BaseQuestion

Returns a new instance of BaseQuestion.



30
31
32
33
34
# File 'lib/k_starter/questions/base_question.rb', line 30

def initialize(**args)
  initialize_attributes(**args)
  apply_attribute_defaults
  clean_attributes
end

Instance Attribute Details

#actorObject (readonly)

who is the actor



23
24
25
# File 'lib/k_starter/questions/base_question.rb', line 23

def actor
  @actor
end

#descriptionObject (readonly)

project description



21
22
23
# File 'lib/k_starter/questions/base_question.rb', line 21

def description
  @description
end

#github_keyObject (readonly)

github user_name or organization name



20
21
22
# File 'lib/k_starter/questions/base_question.rb', line 20

def github_key
  @github_key
end

#klue_template_activeObject (readonly)

is klue_template used?



27
28
29
# File 'lib/k_starter/questions/base_question.rb', line 27

def klue_template_active
  @klue_template_active
end

#klue_template_nameObject (readonly)

name of the klue template



28
29
30
# File 'lib/k_starter/questions/base_question.rb', line 28

def klue_template_name
  @klue_template_name
end

#nameObject (readonly)

project name



15
16
17
# File 'lib/k_starter/questions/base_question.rb', line 15

def name
  @name
end

#problemObject (readonly)

what problem do they have



24
25
26
# File 'lib/k_starter/questions/base_question.rb', line 24

def problem
  @problem
end

#root_pathObject (readonly)

project root path



18
19
20
# File 'lib/k_starter/questions/base_question.rb', line 18

def root_path
  @root_path
end

#solutionObject (readonly)

what is the intended solution



25
26
27
# File 'lib/k_starter/questions/base_question.rb', line 25

def solution
  @solution
end

#story_activeObject (readonly)

is story required?



22
23
24
# File 'lib/k_starter/questions/base_question.rb', line 22

def story_active
  @story_active
end

#sub_pathObject (readonly)

project sub path, useful for folders under the root such as klueless projects



19
20
21
# File 'lib/k_starter/questions/base_question.rb', line 19

def sub_path
  @sub_path
end

#typeObject (readonly)

project type



16
17
18
# File 'lib/k_starter/questions/base_question.rb', line 16

def type
  @type
end

#user_storyObject (readonly)

what is the primary user story



26
27
28
# File 'lib/k_starter/questions/base_question.rb', line 26

def user_story
  @user_story
end

#variantObject (readonly)

project variant



17
18
19
# File 'lib/k_starter/questions/base_question.rb', line 17

def variant
  @variant
end

Instance Method Details

#ask_actorObject



77
78
79
80
# File 'lib/k_starter/questions/base_question.rb', line 77

def ask_actor
  @actor = prompt.ask('Who is the primary actor for this project?', default: @actor || 'Developer')
  # show_story(actor: @actor)
end

#ask_descriptionObject



67
68
69
# File 'lib/k_starter/questions/base_question.rb', line 67

def ask_description
  @description = question.ask('Description', default: @description)
end

#ask_github_keyObject



62
63
64
65
# File 'lib/k_starter/questions/base_question.rb', line 62

def ask_github_key
  choices = [App.config.github_user] + App.config.github_organizations
  @github_key = prompt.select('Select Github user or organization', choices, cycle: true, filter: true, default: @github_key)
end

#ask_klue_template_active?Boolean

ask_user_story

Returns:

  • (Boolean)


111
112
113
114
# File 'lib/k_starter/questions/base_question.rb', line 111

def ask_klue_template_active?
  @klue_template_active = question.yes?('Does this project use a Klue Templates?', default: @klue_template_active)
  @klue_template_active
end

#ask_klue_template_nameObject



116
117
118
119
120
121
# File 'lib/k_starter/questions/base_question.rb', line 116

def ask_klue_template_name
  prompt.warn('Location: ~/dev/kgems/k_templates/definitions/starter')
  @klue_template_name = prompt.ask('Klue starter template name', default: infer_klue_template_name(@klue_template_name)) do |q|
    q.required(true)
  end
end

#ask_problemObject



82
83
84
85
# File 'lib/k_starter/questions/base_question.rb', line 82

def ask_problem
  @problem = question.ask('What problem are you solving?', default: @problem)
  # show_story(actor: @actor, problem: @problem)
end

#ask_root_pathObject



42
43
44
45
46
47
48
49
50
# File 'lib/k_starter/questions/base_question.rb', line 42

def ask_root_path
  project_type_config = App.config.get_project_type(type, variant)
  configured_path = project_type_config.nil? ? '~/unknown_project' : project_type_config[:path]

  @root_path = question.ask('Root project path') do |q|
    q.default(configured_path)
    q.required(true)
  end
end

#ask_solutionObject



87
88
89
90
# File 'lib/k_starter/questions/base_question.rb', line 87

def ask_solution
  @solution = question.ask('What is the intended solution?', default: @solution)
  # show_story(actor: @actor, problem: @problem, solution: @solution)
end

#ask_story_active?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/k_starter/questions/base_question.rb', line 71

def ask_story_active?
  @story_active = question.yes?('Is a user story required?', default: @story_active)
  show_story(actor: @actor, problem: @problem, solution: @solution)
  @story_active
end

#ask_sub_pathObject



52
53
54
55
56
57
58
59
60
# File 'lib/k_starter/questions/base_question.rb', line 52

def ask_sub_path
  project_type_config = App.config.get_project_type(type, variant)
  configured_path = project_type_config.nil? ? '~/unknown_project' : project_type_config[:sub_path]

  @sub_path = question.ask('Sub path within the project') do |q|
    q.default(configured_path)
    q.required(true)
  end
end

#ask_user_storyObject



96
97
98
# File 'lib/k_starter/questions/base_question.rb', line 96

def ask_user_story
  @user_story = question.ask('User Story', default: "As a #{actor}, I want to #{problem} so that I can #{solution}")
end

#default_klue_template_activeObject



146
147
148
# File 'lib/k_starter/questions/base_question.rb', line 146

def default_klue_template_active
  @klue_template_active = true if @klue_template_active.nil?
end

#default_questionsObject



36
# File 'lib/k_starter/questions/base_question.rb', line 36

def default_questions; end

#default_story_activeObject



142
143
144
# File 'lib/k_starter/questions/base_question.rb', line 142

def default_story_active
  @story_active = true if @story_active.nil?
end

#infer_klue_template_name(klue_template_name) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/k_starter/questions/base_question.rb', line 129

def infer_klue_template_name(klue_template_name)
  return klue_template_name unless klue_template_name.nil?

  case type
  when :rails, :svelte, :nuxt3
    return type.to_s
  when :gem
    # return variant == :library ? 'ruby_gem' : 'ruby_gem_cli'
    return 'ruby_gem'
  end
  nil
end

#klue_template_questionsObject



123
124
125
126
127
# File 'lib/k_starter/questions/base_question.rb', line 123

def klue_template_questions
  return unless ask_klue_template_active?

  ask_klue_template_name
end

#questionObject



38
39
40
# File 'lib/k_starter/questions/base_question.rb', line 38

def question
  @question ||= prompt
end

#show_story(**args) ⇒ Object



92
93
94
# File 'lib/k_starter/questions/base_question.rb', line 92

def show_story(**args)
  prompt.warn("As a #{args[:actor] || 'ACTOR'}, I want to #{args[:problem] || 'SOLVE PROBLEM'} so that I can #{args[:solution] || 'HAVE BENEFIT'}")
end

#story_questionsObject



100
101
102
103
104
105
106
107
# File 'lib/k_starter/questions/base_question.rb', line 100

def story_questions
  return unless ask_story_active?

  ask_actor
  ask_problem
  ask_solution
  ask_user_story
end

#to_hObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/k_starter/questions/base_question.rb', line 150

def to_h
  {
    name: name,
    type: type,
    variant: variant,
    root_path: root_path,
    description: description,
    github_key: github_key,
    story: {
      active: story_active,
      actor: actor,
      problem: problem,
      solution: solution,
      user_story: user_story
    },
    klue_template: {
      active: klue_template_active,
      name: klue_template_name
    }
  }
end