class Rake::DevEiate::GemDepFinder

A dependency finder that groks the GemDependencyApi

Attributes

current_groups[R]

The current set of groups to add to any declared gems

dependencies[R]

The Set of Gem::Dependency objects that describe the loaded dependencies

depfile[R]

The Pathname of the file to find dependencies in

Public Class Methods

new( depfile ) click to toggle source

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

Public Instance Methods

gem( name, *requirements, **options ) click to toggle source

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
gemspec( * ) click to toggle source

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
group( *names ) { || ... } click to toggle source

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() click to toggle source

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