Class: Scaffolding
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Scaffolding
- Includes:
- Thor::Actions
- Defined in:
- lib/scaffolding/scaffolding.rb
Constant Summary collapse
- OVERRIDE_DIR =
'.ruby_raider/templates'
Instance Attribute Summary collapse
-
#introspected ⇒ Object
readonly
Returns the value of attribute introspected.
-
#url_data ⇒ Object
readonly
Returns the value of attribute url_data.
-
#uses ⇒ Object
writeonly
Sets the attribute uses.
Class Method Summary collapse
-
.planned_path(name, type, custom_path = nil) ⇒ Object
— Path planning (for dry-run) —.
- .source_root ⇒ Object
Instance Method Summary collapse
- #ai_scenarios ⇒ Object
- #automation_type ⇒ Object
- #capybara? ⇒ Boolean
-
#class_name ⇒ Object
— Template helpers (available in .tt files) —.
- #default_path(standard_path, file_type) ⇒ Object
- #delete_component ⇒ Object
- #delete_config ⇒ Object
- #delete_feature ⇒ Object
- #delete_helper ⇒ Object
-
#delete_page ⇒ Object
— Deletion methods —.
- #delete_spec ⇒ Object
- #delete_steps ⇒ Object
- #framework_type ⇒ Object
- #generate_component ⇒ Object
- #generate_config ⇒ Object
- #generate_feature ⇒ Object
- #generate_helper ⇒ Object
-
#generate_page ⇒ Object
— Generation methods —.
- #generate_page_from_url(analysis) ⇒ Object
- #generate_spec ⇒ Object
-
#generate_spec_from_page(source_file, ai: false) ⇒ Object
rubocop:disable Naming/MethodParameterName.
- #generate_spec_from_url(analysis) ⇒ Object
- #generate_steps ⇒ Object
- #leaf_name ⇒ Object
- #module_parts ⇒ Object
- #nested? ⇒ Boolean
- #normalized_name ⇒ Object
- #page_class_name ⇒ Object
- #project_config ⇒ Object
- #selenium? ⇒ Boolean
-
#template(source, *args, &block) ⇒ Object
Check for user template override before using default.
- #uses_list ⇒ Object
- #watir? ⇒ Boolean
Instance Attribute Details
#introspected ⇒ Object (readonly)
Returns the value of attribute introspected.
179 180 181 |
# File 'lib/scaffolding/scaffolding.rb', line 179 def introspected @introspected end |
#url_data ⇒ Object (readonly)
Returns the value of attribute url_data.
179 180 181 |
# File 'lib/scaffolding/scaffolding.rb', line 179 def url_data @url_data end |
#uses=(value) ⇒ Object (writeonly)
Sets the attribute uses
14 15 16 |
# File 'lib/scaffolding/scaffolding.rb', line 14 def uses=(value) @uses = value end |
Class Method Details
.planned_path(name, type, custom_path = nil) ⇒ Object
— Path planning (for dry-run) —
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/scaffolding/scaffolding.rb', line 112 def self.planned_path(name, type, custom_path = nil) n = NameNormalizer.normalize(name) case type.to_s when 'page' then custom_path ? "#{custom_path}/#{n}_page.rb" : "page_objects/pages/#{n}.rb" when 'spec' then custom_path ? "#{custom_path}/#{n}_spec.rb" : "spec/#{n}_page_spec.rb" when 'feature' then custom_path ? "#{custom_path}/#{n}.feature" : "features/#{n}.feature" when 'steps' then custom_path ? "#{custom_path}/#{n}_steps.rb" : "features/step_definitions/#{n}_steps.rb" when 'helper' then custom_path ? "#{custom_path}/#{n}_helper.rb" : "helpers/#{n}_helper.rb" when 'component' then custom_path ? "#{custom_path}/#{n}.rb" : "page_objects/components/#{n}.rb" when 'model' then "models/data/#{n}.yml" end end |
.source_root ⇒ Object
18 19 20 |
# File 'lib/scaffolding/scaffolding.rb', line 18 def self.source_root "#{File.dirname(__FILE__)}/templates" end |
Instance Method Details
#ai_scenarios ⇒ Object
181 182 183 |
# File 'lib/scaffolding/scaffolding.rb', line 181 def ai_scenarios @ai_scenarios || {} end |
#automation_type ⇒ Object
151 152 153 |
# File 'lib/scaffolding/scaffolding.rb', line 151 def automation_type ScaffoldProjectDetector.detect_automation end |
#capybara? ⇒ Boolean
167 168 169 |
# File 'lib/scaffolding/scaffolding.rb', line 167 def automation_type == 'capybara' end |
#class_name ⇒ Object
— Template helpers (available in .tt files) —
127 128 129 |
# File 'lib/scaffolding/scaffolding.rb', line 127 def class_name NameNormalizer.to_class_name(name) end |
#default_path(standard_path, file_type) ⇒ Object
185 186 187 |
# File 'lib/scaffolding/scaffolding.rb', line 185 def default_path(standard_path, file_type) path ? "#{path}/#{normalized_name}#{file_type}" : standard_path end |
#delete_component ⇒ Object
102 103 104 |
# File 'lib/scaffolding/scaffolding.rb', line 102 def delete_component remove_file(default_path("page_objects/components/#{normalized_name}.rb", '.rb')) end |
#delete_config ⇒ Object
106 107 108 |
# File 'lib/scaffolding/scaffolding.rb', line 106 def delete_config remove_file(default_path('config/config.yml', '.yml')) end |
#delete_feature ⇒ Object
86 87 88 |
# File 'lib/scaffolding/scaffolding.rb', line 86 def delete_feature remove_file(default_path("features/#{normalized_name}.feature", '.feature')) end |
#delete_helper ⇒ Object
94 95 96 |
# File 'lib/scaffolding/scaffolding.rb', line 94 def delete_helper remove_file(default_path("helpers/#{normalized_name}_helper.rb", '_helper.rb')) end |
#delete_page ⇒ Object
— Deletion methods —
82 83 84 |
# File 'lib/scaffolding/scaffolding.rb', line 82 def delete_page remove_file(default_path("page_objects/pages/#{normalized_name}.rb", '_page.rb')) end |
#delete_spec ⇒ Object
90 91 92 |
# File 'lib/scaffolding/scaffolding.rb', line 90 def delete_spec remove_file(default_path("spec/#{normalized_name}_page_spec.rb", '_spec.rb')) end |
#delete_steps ⇒ Object
98 99 100 |
# File 'lib/scaffolding/scaffolding.rb', line 98 def delete_steps remove_file(default_path("features/step_definitions/#{normalized_name}_steps.rb", '_steps.rb')) end |
#framework_type ⇒ Object
155 156 157 |
# File 'lib/scaffolding/scaffolding.rb', line 155 def framework_type ScaffoldProjectDetector.detect_framework end |
#generate_component ⇒ Object
54 55 56 |
# File 'lib/scaffolding/scaffolding.rb', line 54 def generate_component template('component.tt', default_path("page_objects/components/#{normalized_name}.rb", '.rb')) end |
#generate_config ⇒ Object
58 59 60 61 |
# File 'lib/scaffolding/scaffolding.rb', line 58 def generate_config template('../../generators/templates/common/config.tt', default_path('config/config.yml', '.yml')) end |
#generate_feature ⇒ Object
38 39 40 |
# File 'lib/scaffolding/scaffolding.rb', line 38 def generate_feature template('feature.tt', default_path("features/#{normalized_name}.feature", '.feature')) end |
#generate_helper ⇒ Object
46 47 48 |
# File 'lib/scaffolding/scaffolding.rb', line 46 def generate_helper template('helper.tt', default_path("helpers/#{normalized_name}_helper.rb", '_helper.rb')) end |
#generate_page ⇒ Object
— Generation methods —
34 35 36 |
# File 'lib/scaffolding/scaffolding.rb', line 34 def generate_page template('page_object.tt', default_path("page_objects/pages/#{normalized_name}.rb", '_page.rb')) end |
#generate_page_from_url(analysis) ⇒ Object
70 71 72 73 |
# File 'lib/scaffolding/scaffolding.rb', line 70 def generate_page_from_url(analysis) @url_data = analysis template('page_from_url.tt', "page_objects/pages/#{normalized_name}.rb") end |
#generate_spec ⇒ Object
42 43 44 |
# File 'lib/scaffolding/scaffolding.rb', line 42 def generate_spec template('spec.tt', default_path("spec/#{normalized_name}_page_spec.rb", '_spec.rb')) end |
#generate_spec_from_page(source_file, ai: false) ⇒ Object
rubocop:disable Naming/MethodParameterName
63 64 65 66 67 68 |
# File 'lib/scaffolding/scaffolding.rb', line 63 def generate_spec_from_page(source_file, ai: false) # rubocop:disable Naming/MethodParameterName require_relative 'page_introspector' @introspected = PageIntrospector.new(source_file) enrich_with_ai_scenarios if ai template('spec_from_page.tt', "spec/#{normalized_name}_spec.rb") end |
#generate_spec_from_url(analysis) ⇒ Object
75 76 77 78 |
# File 'lib/scaffolding/scaffolding.rb', line 75 def generate_spec_from_url(analysis) @url_data = analysis template('spec_from_url.tt', "spec/#{normalized_name}_spec.rb") end |
#generate_steps ⇒ Object
50 51 52 |
# File 'lib/scaffolding/scaffolding.rb', line 50 def generate_steps template('steps.tt', default_path("features/step_definitions/#{normalized_name}_steps.rb", '_steps.rb')) end |
#leaf_name ⇒ Object
147 148 149 |
# File 'lib/scaffolding/scaffolding.rb', line 147 def leaf_name NameNormalizer.leaf_name(name) end |
#module_parts ⇒ Object
143 144 145 |
# File 'lib/scaffolding/scaffolding.rb', line 143 def module_parts NameNormalizer.module_parts(name) end |
#nested? ⇒ Boolean
139 140 141 |
# File 'lib/scaffolding/scaffolding.rb', line 139 def nested? NameNormalizer.nested?(name) end |
#normalized_name ⇒ Object
135 136 137 |
# File 'lib/scaffolding/scaffolding.rb', line 135 def normalized_name NameNormalizer.normalize(name) end |
#page_class_name ⇒ Object
131 132 133 |
# File 'lib/scaffolding/scaffolding.rb', line 131 def page_class_name NameNormalizer.to_page_class(name) end |
#project_config ⇒ Object
159 160 161 |
# File 'lib/scaffolding/scaffolding.rb', line 159 def project_config ScaffoldProjectDetector.config end |
#selenium? ⇒ Boolean
163 164 165 |
# File 'lib/scaffolding/scaffolding.rb', line 163 def selenium? automation_type == 'selenium' end |
#template(source, *args, &block) ⇒ Object
Check for user template override before using default
23 24 25 26 27 28 29 30 |
# File 'lib/scaffolding/scaffolding.rb', line 23 def template(source, *args, &block) override = File.join(OVERRIDE_DIR, File.basename(source)) if File.exist?(override) super(File.(override), *args, &block) else super end end |
#uses_list ⇒ Object
175 176 177 |
# File 'lib/scaffolding/scaffolding.rb', line 175 def uses_list Array(@uses).reject(&:empty?) end |
#watir? ⇒ Boolean
171 172 173 |
# File 'lib/scaffolding/scaffolding.rb', line 171 def watir? automation_type == 'watir' end |