Class: Rake::DevEiate::GemDepFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/deveiate/gem_dep_finder.rb

Overview

A dependency finder that groks the GemDependencyApi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depfile) ⇒ GemDepFinder

Create a new GemDepFinder that will find dependencies in the given depfile.



14
15
16
17
18
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 14

def initialize( depfile )
  @depfile = Pathname( depfile )
  @dependencies = Set.new
  @current_groups = Set.new
end

Instance Attribute Details

#current_groupsObject (readonly)

The current set of groups to add to any declared gems



36
37
38
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 36

def current_groups
  @current_groups
end

#dependenciesObject (readonly)

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



32
33
34
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 32

def dependencies
  @dependencies
end

#depfileObject (readonly)

The Pathname of the file to find dependencies in



28
29
30
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 28

def depfile
  @depfile
end

Instance Method Details

#gem(name, *requirements, **options) ⇒ Object

Declare a dependency on a gem. Ignores every option except :group.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 52

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

#gemspecObject

Raise, as the gemdeps file should be the authoritative source.



79
80
81
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 79

def gemspec( * )
  raise "Circular dependency: can't depend on the gemspec to build itself"
end

#group(*names) ⇒ Object

Declare a group block.



67
68
69
70
71
72
73
74
75
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 67

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

#loadObject

Load the dependencies file.



40
41
42
43
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 40

def load
  source = self.depfile.read
  self.instance_eval( source, self.depfile.to_s, 1 )
end

#no_op_methodObject Also known as: source, git, platform, platforms, ruby

Ignore a gem dependency API call.



85
86
87
# File 'lib/rake/deveiate/gem_dep_finder.rb', line 85

def no_op_method( * ) # :nodoc:
  yield if block_given?
end