Class: Rails::Diff::RailsRepo
- Inherits:
-
Object
- Object
- Rails::Diff::RailsRepo
- Defined in:
- lib/rails/diff/rails_repo.rb
Constant Summary collapse
- RAILS_REPO =
"https://github.com/rails/rails.git"
Instance Method Summary collapse
- #checkout(commit) ⇒ Object
-
#initialize(logger:, cache_dir: Rails::Diff::CACHE_DIR, rails_repo: RAILS_REPO) ⇒ RailsRepo
constructor
A new instance of RailsRepo.
- #install_dependencies ⇒ Object
- #latest_commit ⇒ Object
- #new_app(name, options) ⇒ Object
- #up_to_date? ⇒ Boolean
- #within(dir, &block) ⇒ Object
Constructor Details
#initialize(logger:, cache_dir: Rails::Diff::CACHE_DIR, rails_repo: RAILS_REPO) ⇒ RailsRepo
Returns a new instance of RailsRepo.
6 7 8 9 10 |
# File 'lib/rails/diff/rails_repo.rb', line 6 def initialize(logger:, cache_dir: Rails::Diff::CACHE_DIR, rails_repo: RAILS_REPO) @logger = logger @cache_dir = cache_dir @rails_repo = rails_repo end |
Instance Method Details
#checkout(commit) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/rails/diff/rails_repo.rb', line 12 def checkout(commit) on_rails_dir do logger.info "Checking out Rails (at commit #{commit[0..6]})" Rails::Diff.system!("git", "checkout", commit, logger: logger) end end |
#install_dependencies ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/rails/diff/rails_repo.rb', line 30 def install_dependencies within "railties" do unless Rails::Diff.system!("bundle check", abort: false, logger: logger) logger.info "Installing Rails dependencies" Rails::Diff.system!("bundle install", logger: logger) end end end |
#latest_commit ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rails/diff/rails_repo.rb', line 19 def latest_commit @latest_commit ||= on_rails_dir do Rails::Diff.system!("git fetch origin main", logger: logger) `git rev-parse origin/main`.strip end end |
#new_app(name, options) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/rails/diff/rails_repo.rb', line 39 def new_app(name, ) within "railties" do command = rails_new_command(name, ) logger.info "Generating new Rails application\n\t > #{command.join(" ")}" Rails::Diff.system!(*command, logger: logger) end end |
#up_to_date? ⇒ Boolean
26 27 28 |
# File 'lib/rails/diff/rails_repo.rb', line 26 def up_to_date? File.exist?(rails_path) && on_latest_commit? end |
#within(dir, &block) ⇒ Object
47 |
# File 'lib/rails/diff/rails_repo.rb', line 47 def within(dir, &block) = on_rails_dir { Dir.chdir(dir, &block) } |