Class: Bundler::Dependencies::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/dependencies/spec.rb

Constant Summary collapse

SPECS =

rubocop:disable Style/MutableConstant

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Spec

Returns a new instance of Spec.



21
22
23
24
25
26
# File 'lib/bundler/dependencies/spec.rb', line 21

def initialize(name)
  @name = name
  @dependencies = Graph.new

  SPECS[name] = self
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



8
9
10
# File 'lib/bundler/dependencies/spec.rb', line 8

def dependencies
  @dependencies
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/bundler/dependencies/spec.rb', line 8

def name
  @name
end

Class Method Details

.find(name) ⇒ Object



17
18
19
# File 'lib/bundler/dependencies/spec.rb', line 17

def self.find(name)
  SPECS[name.to_sym]
end

.new(name, dependencies = []) ⇒ Object



10
11
12
13
14
15
# File 'lib/bundler/dependencies/spec.rb', line 10

def self.new(name, dependencies = [])
  name = name.to_sym
  spec = find(name) || super(name)
  spec.dependencies = Graph.new(specs: dependencies.map { |d| new(d) }) if dependencies.any?
  spec
end

Instance Method Details

#dependency_countObject



39
40
41
# File 'lib/bundler/dependencies/spec.rb', line 39

def dependency_count
  flatten.count
end

#flattenObject



32
33
34
35
36
37
# File 'lib/bundler/dependencies/spec.rb', line 32

def flatten
  dependencies.inject([]) do |arr, dependency|
    arr << dependency
    arr.concat(dependency.flatten)
  end.uniq
end

#include_dependency?(gem) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/bundler/dependencies/spec.rb', line 28

def include_dependency?(gem)
  dependencies.include_dependency?(gem)
end