Skip to content

Commit

Permalink
Push down gems_to_generate to subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrocha committed Dec 6, 2024
1 parent 1705eb0 commit 990eb7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
33 changes: 0 additions & 33 deletions lib/tapioca/commands/abstract_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,39 +73,6 @@ def initialize(

private

sig { params(gem_names: T::Array[String]).returns(T::Array[Gemfile::GemSpec]) }
def gems_to_generate(gem_names)
return @bundle.dependencies if gem_names.empty?

(gem_names - @exclude).each_with_object([]) do |gem_name, gems|
gem = @bundle.gem(gem_name)

if gem.nil?
raise Thor::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
end

gems.concat(gem_dependencies(gem)) if @include_dependencies
gems << gem
end
end

sig do
params(
gem: Gemfile::GemSpec,
dependencies: T::Array[Gemfile::GemSpec],
).returns(T::Array[Gemfile::GemSpec])
end
def gem_dependencies(gem, dependencies = [])
direct_dependencies = gem.dependencies.filter_map { |dependency| @bundle.gem(dependency.name) }
gems = dependencies | direct_dependencies

if direct_dependencies.empty?
gems
else
direct_dependencies.reduce(gems) { |result, gem| gem_dependencies(gem, result) }
end
end

sig { params(gem: Gemfile::GemSpec).void }
def compile_gem_rbi(gem)
gem_name = set_color(gem.name, :yellow, :bold)
Expand Down
33 changes: 33 additions & 0 deletions lib/tapioca/commands/gem_generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,39 @@ def execute
ensure
GitAttributes.create_generated_attribute_file(@outpath)
end

sig { params(gem_names: T::Array[String]).returns(T::Array[Gemfile::GemSpec]) }
def gems_to_generate(gem_names)
return @bundle.dependencies if gem_names.empty?

(gem_names - @exclude).each_with_object([]) do |gem_name, gems|
gem = @bundle.gem(gem_name)

if gem.nil?
raise Thor::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
end

gems.concat(gem_dependencies(gem)) if @include_dependencies
gems << gem
end
end

sig do
params(
gem: Gemfile::GemSpec,
dependencies: T::Array[Gemfile::GemSpec],
).returns(T::Array[Gemfile::GemSpec])
end
def gem_dependencies(gem, dependencies = [])
direct_dependencies = gem.dependencies.filter_map { |dependency| @bundle.gem(dependency.name) }
gems = dependencies | direct_dependencies

if direct_dependencies.empty?
gems
else
direct_dependencies.reduce(gems) { |result, gem| gem_dependencies(gem, result) }
end
end
end
end
end

0 comments on commit 990eb7d

Please sign in to comment.