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.



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

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

  SPECS[name] = self
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



6
7
8
# File 'lib/bundler/dependencies/spec.rb', line 6

def dependencies
  @dependencies
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/bundler/dependencies/spec.rb', line 6

def name
  @name
end

Class Method Details

.find(name) ⇒ Object



15
16
17
# File 'lib/bundler/dependencies/spec.rb', line 15

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

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



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

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



37
38
39
# File 'lib/bundler/dependencies/spec.rb', line 37

def dependency_count
  flatten.count
end

#flattenObject



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

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

#include_dependency?(gem) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/bundler/dependencies/spec.rb', line 26

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