Skip to content

Commit

Permalink
Add support for tapioca sync --verify
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcarbs committed Jun 19, 2021
1 parent 5da4c61 commit 1623c94
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/tapioca/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ def generate(*gems)
end

desc "sync", "sync RBIs to Gemfile"
option :verify,
type: :boolean,
default: false,
desc: "Verifies RBIs are up-to-date"
def sync
Tapioca.silence_warnings do
generator.sync_rbis_with_gemfile
generator.sync_rbis_with_gemfile(should_verify: options[:verify])
end
end

Expand Down
47 changes: 45 additions & 2 deletions lib/tapioca/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,15 @@ def build_dsl(requested_constants, should_verify: false, quiet: false)
end
end

sig { void }
def sync_rbis_with_gemfile
sig { params(should_verify: T::Boolean).void }
def sync_rbis_with_gemfile(should_verify: false)
if should_verify
say("Checking for out-of-date RBIs...")
say("")
perform_sync_verification
return
end

anything_done = [
perform_removals,
perform_additions,
Expand Down Expand Up @@ -624,5 +631,41 @@ def purge_stale_dsl_rbi_files(files)
say("")
end
end

sig { void }
def perform_sync_verification
diff = {}

removed_rbis.each do |gem_name|
filename = existing_rbi(gem_name)
diff[filename] = :removed
end

added_rbis.each do |gem_name|
filename = expected_rbi(gem_name)
if gem_rbi_exists?(gem_name)
diff[filename] = :changed
else
diff[filename] = :added
end
end

if diff.empty?
say("Nothing to do, all RBIs are up-to-date.")
else
say("RBI files are out-of-date. In your development environment, please run:", :green)
say(" `#{Config::DEFAULT_COMMAND} sync`", [:green, :bold])
say("Once it is complete, be sure to commit and push any changes", :green)

say("")

say("Reason:", [:red])
diff.group_by(&:last).sort.each do |cause, diff_for_cause|
say(build_error_for_files(cause, diff_for_cause.map(&:first)))
end

exit(1)
end
end
end
end

0 comments on commit 1623c94

Please sign in to comment.