Class: Rails::Diff::RailsAppGenerator
- Inherits:
-
Object
- Object
- Rails::Diff::RailsAppGenerator
- Defined in:
- lib/rails/diff/rails_app_generator.rb
Constant Summary collapse
- RAILSRC_PATH =
"#{ENV["HOME"]}/.railsrc"
Instance Method Summary collapse
- #clear_cache ⇒ Object
- #create_template_app ⇒ Object
-
#initialize(commit: nil, new_app_options: nil, no_cache: false, logger: Logger, cache_dir: Rails::Diff::CACHE_DIR) ⇒ RailsAppGenerator
constructor
A new instance of RailsAppGenerator.
- #install_app_dependencies ⇒ Object
- #run_generator(generator_name, *args, skip, only) ⇒ Object
- #template_app_path ⇒ Object
Constructor Details
#initialize(commit: nil, new_app_options: nil, no_cache: false, logger: Logger, cache_dir: Rails::Diff::CACHE_DIR) ⇒ RailsAppGenerator
8 9 10 11 12 13 14 15 |
# File 'lib/rails/diff/rails_app_generator.rb', line 8 def initialize(commit: nil, new_app_options: nil, no_cache: false, logger: Logger, cache_dir: Rails::Diff::CACHE_DIR) = .to_s.split @rails_repo = RailsRepo.new(logger:, cache_dir:) @commit = commit @logger = logger @cache_dir = cache_dir clear_cache if no_cache end |
Instance Method Details
#clear_cache ⇒ Object
17 18 19 20 21 |
# File 'lib/rails/diff/rails_app_generator.rb', line 17 def clear_cache logger.info "Clearing cache" FileUtils.rm_rf(cache_dir, secure: true) FileUtils.mkdir_p(cache_dir) end |
#create_template_app ⇒ Object
23 24 25 26 27 |
# File 'lib/rails/diff/rails_app_generator.rb', line 23 def create_template_app return if cached_app? create_new_rails_app end |
#install_app_dependencies ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rails/diff/rails_app_generator.rb', line 33 def install_app_dependencies Dir.chdir(template_app_path) do unless Rails::Diff.system!("bundle check", abort: false, logger: logger) logger.info "Installing application dependencies" Rails::Diff.system!("bundle install", logger: logger) end end end |
#run_generator(generator_name, *args, skip, only) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rails/diff/rails_app_generator.rb', line 42 def run_generator(generator_name, *args, skip, only) Dir.chdir(template_app_path) do Rails::Diff.system!("bin/rails", "destroy", generator_name, *args, logger: logger) logger.info "Running generator: rails generate #{generator_name} #{args.join(" ")}" FileTracker.new(template_app_path, skip, only) .new_files { Rails::Diff.system!("bin/rails", "generate", generator_name, *args, logger: logger) } .map { |it| it.delete_prefix("#{template_app_path}/") } end end |
#template_app_path ⇒ Object
29 30 31 |
# File 'lib/rails/diff/rails_app_generator.rb', line 29 def template_app_path @template_app_path ||= File.join(cache_dir, rails_cache_dir_key, , app_name) end |