Class: KStarter::Questions::BaseQuestion
- Inherits:
-
Object
- Object
- KStarter::Questions::BaseQuestion
show all
- Includes:
- TtyHelpers
- Defined in:
- lib/k_starter/questions/base_question.rb
Overview
Ask code generations for a new projects.
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
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
#actor ⇒ Object
23
24
25
|
# File 'lib/k_starter/questions/base_question.rb', line 23
def actor
@actor
end
|
#description ⇒ Object
21
22
23
|
# File 'lib/k_starter/questions/base_question.rb', line 21
def description
@description
end
|
#github_key ⇒ Object
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_active ⇒ Object
27
28
29
|
# File 'lib/k_starter/questions/base_question.rb', line 27
def klue_template_active
@klue_template_active
end
|
#klue_template_name ⇒ Object
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
|
#name ⇒ Object
15
16
17
|
# File 'lib/k_starter/questions/base_question.rb', line 15
def name
@name
end
|
#problem ⇒ Object
what problem do they have
24
25
26
|
# File 'lib/k_starter/questions/base_question.rb', line 24
def problem
@problem
end
|
#root_path ⇒ Object
18
19
20
|
# File 'lib/k_starter/questions/base_question.rb', line 18
def root_path
@root_path
end
|
#solution ⇒ Object
what is the intended solution
25
26
27
|
# File 'lib/k_starter/questions/base_question.rb', line 25
def solution
@solution
end
|
#story_active ⇒ Object
22
23
24
|
# File 'lib/k_starter/questions/base_question.rb', line 22
def story_active
@story_active
end
|
#sub_path ⇒ Object
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
|
#type ⇒ Object
16
17
18
|
# File 'lib/k_starter/questions/base_question.rb', line 16
def type
@type
end
|
#user_story ⇒ Object
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
|
#variant ⇒ Object
17
18
19
|
# File 'lib/k_starter/questions/base_question.rb', line 17
def variant
@variant
end
|
Instance Method Details
#ask_actor ⇒ Object
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')
end
|
#ask_description ⇒ Object
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_key ⇒ Object
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
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_name ⇒ Object
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_problem ⇒ Object
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)
end
|
#ask_root_path ⇒ Object
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_solution ⇒ Object
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)
end
|
#ask_story_active? ⇒ 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_path ⇒ Object
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_story ⇒ Object
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_active ⇒ Object
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_questions ⇒ Object
36
|
# File 'lib/k_starter/questions/base_question.rb', line 36
def default_questions; end
|
#default_story_active ⇒ Object
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 'ruby_gem'
end
nil
end
|
#klue_template_questions ⇒ Object
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
|
#question ⇒ Object
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_questions ⇒ Object
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_h ⇒ Object
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
|