A dependency finder that groks the GemDependencyApi
The current set of groups to add to any declared gems
The Set of Gem::Dependency objects that describe the loaded dependencies
The Pathname of the file to find dependencies in
Create a new GemDepFinder
that will find dependencies in the given depfile
.
# File lib/rake/deveiate/gem_dep_finder.rb, line 13
def initialize( depfile )
@depfile = Pathname( depfile )
@dependencies = Set.new
@current_groups = Set.new
end
Declare a dependency on a gem. Ignores every option except :group.
# File lib/rake/deveiate/gem_dep_finder.rb, line 51
def gem( name, *requirements, **options )
if options[:group] == :development ||
options[:groups]&.include?( :development ) ||
self.current_groups.include?( :development )
requirements.push( :development )
end
dependency = Gem::Dependency.new( name, *requirements )
self.dependencies.add( dependency )
end
Raise, as the gemdeps file should be the authoritative source.
# File lib/rake/deveiate/gem_dep_finder.rb, line 78
def gemspec( * )
raise "Circular dependency: can't depend on the gemspec to build itself"
end
Declare a group block.
# File lib/rake/deveiate/gem_dep_finder.rb, line 66
def group( *names )
options = names.pop if names.last.is_a?( Hash )
previous_groups = self.current_groups.dup
self.current_groups.replace( names )
yield
ensure
self.current_groups.replace( previous_groups ) if previous_groups
end
Load the dependencies file.
# File lib/rake/deveiate/gem_dep_finder.rb, line 39
def load
source = self.depfile.read
self.instance_eval( source, self.depfile.to_s, 1 )
end