Class: RailsAppGenerator::Starter
- Inherits:
-
Object
- Object
- RailsAppGenerator::Starter
- Defined in:
- lib/rails_app_generator/starter.rb
Overview
Starter is a wrapper for Rails::AppGenerator
example:
RailsAppGenerator::Starter.new.start
RailsAppGenerator::Starter.new(app_path: '.', destination_root: Dir.pwd).start
RailsAppGenerator::Starter.new(app_path: 'xmen', destination_root: '~/projects_path').start
RailsAppGenerator::Starter.new(app_path: '.', destination_root: '~/projects_path/xmen').start
Instance Attribute Summary collapse
-
#addon_template_path ⇒ Object
readonly
points to templates related to rails addons.
-
#app_path ⇒ Object
readonly
include KLog::Logging.
-
#capture_output ⇒ Object
readonly
Returns the value of attribute capture_output.
-
#console_output ⇒ Object
readonly
Returns the value of attribute console_output.
-
#destination_root ⇒ Object
readonly
Returns the value of attribute destination_root.
-
#override_template_path ⇒ Object
readonly
points to the overriding templates related to rails.
-
#rails_template_path ⇒ Object
readonly
points to the original rails templates.
-
#when_folder_exist ⇒ Object
readonly
[abort destroy keep_git overwrite].
Instance Method Summary collapse
-
#handle_target_folder_found? ⇒ Boolean
rubocop:disable Metrics/AbcSize.
-
#initialize(**args) ⇒ Starter
constructor
rubocop:disable Metrics/CyclomaticComplexity.
- #start(options = []) ⇒ Object
-
#target_path ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
Constructor Details
#initialize(**args) ⇒ Starter
rubocop:disable Metrics/CyclomaticComplexity
37 38 39 40 41 42 43 44 45 |
# File 'lib/rails_app_generator/starter.rb', line 37 def initialize(**args) @app_path = args[:app_path] || '.' @destination_root = args[:destination_root] || Dir.pwd @rails_template_path = args[:rails_template_path] || AppGenerator.rails_template_path @override_template_path = args[:override_template_path] || AppGenerator.override_template_path @addon_template_path = args[:addon_template_path] || AppGenerator.addon_template_path @when_folder_exist = args[:when_folder_exist] || 'abort' @capture_output = args[:capture_output].nil? ? false : args[:capture_output] end |
Instance Attribute Details
#addon_template_path ⇒ Object (readonly)
points to templates related to rails addons
29 30 31 |
# File 'lib/rails_app_generator/starter.rb', line 29 def addon_template_path @addon_template_path end |
#app_path ⇒ Object (readonly)
include KLog::Logging
19 20 21 |
# File 'lib/rails_app_generator/starter.rb', line 19 def app_path @app_path end |
#capture_output ⇒ Object (readonly)
Returns the value of attribute capture_output.
33 34 35 |
# File 'lib/rails_app_generator/starter.rb', line 33 def capture_output @capture_output end |
#console_output ⇒ Object (readonly)
Returns the value of attribute console_output.
34 35 36 |
# File 'lib/rails_app_generator/starter.rb', line 34 def console_output @console_output end |
#destination_root ⇒ Object (readonly)
Returns the value of attribute destination_root.
20 21 22 |
# File 'lib/rails_app_generator/starter.rb', line 20 def destination_root @destination_root end |
#override_template_path ⇒ Object (readonly)
points to the overriding templates related to rails
26 27 28 |
# File 'lib/rails_app_generator/starter.rb', line 26 def override_template_path @override_template_path end |
#rails_template_path ⇒ Object (readonly)
points to the original rails templates
23 24 25 |
# File 'lib/rails_app_generator/starter.rb', line 23 def rails_template_path @rails_template_path end |
#when_folder_exist ⇒ Object (readonly)
- abort destroy keep_git overwrite
31 32 33 |
# File 'lib/rails_app_generator/starter.rb', line 31 def when_folder_exist @when_folder_exist end |
Instance Method Details
#handle_target_folder_found? ⇒ Boolean
rubocop:disable Metrics/AbcSize
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rails_app_generator/starter.rb', line 67 def handle_target_folder_found? return true unless File.directory?(target_path) case when_folder_exist when 'abort' puts "Target folder [#{target_path}] already exists. Aborting" puts 'Maybe you want to use when_folder_exist option with one of these values [destroy overwrite keep_git]' false when 'destroy' puts "Target folder [#{target_path}] already exists. Destroying it" FileUtils.rm_rf(target_path) true when 'keep_git' puts "Target folder [#{target_path}] already exists. Wiping it but keeping git history" clean_target_folder true when 'overwrite' puts "Target folder [#{target_path}] already exists. Overwriting it" true else raise "Invalid when_folder_exist: #{when_folder_exist}" end end |
#start(options = []) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails_app_generator/starter.rb', line 52 def start( = []) puts "Target path: #{target_path}" opts = (app_path, ) if capture_output @console_output = Util.capture_console do RailsAppGenerator::AppGenerator.start(opts, destination_root: destination_root) end else RailsAppGenerator::AppGenerator.start(opts, destination_root: destination_root) end end |
#target_path ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity
48 49 50 |
# File 'lib/rails_app_generator/starter.rb', line 48 def target_path File.(File.join(destination_root, app_path)) end |