Class: Doubleshot::Dependencies::DependencyList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/doubleshot/dependencies/dependency_list.rb

Direct Known Subclasses

GemDependencyList, JarDependencyList

Constant Summary collapse

DEPENDENCY_CLASS =
Dependency

Instance Method Summary collapse

Constructor Details

#initializeDependencyList

Returns a new instance of DependencyList.



10
11
12
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 10

def initialize
  @dependencies = Set.new
end

Instance Method Details

#+(other) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 19

def +(other)
  if other.class == self.class
    list = self.class.new
    (entries + other.entries).each { |item| list.add item }
    list
  else
    raise ArgumentError.new("Only DependencyLists of the same type may be concatenated." +
      "Expected +other+ to be a #{self.class.inspect} but was a #{other.class.inspect}.")
  end
end

#add(dependency) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 30

def add(dependency)
  unless dependency.is_a? Dependency
    raise ArgumentError.new("+dependency+ must be a Doubleshot::Dependencies::Dependency")
  end
  @dependencies << dependency
  self
end

#eachObject



58
59
60
61
62
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 58

def each
  @dependencies.each do |dependency|
    yield dependency
  end
end

#empty?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 54

def empty?
  @dependencies.empty?
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


14
15
16
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 14

def eql?(other)
  other.is_a?(self.class) && entries == other.entries
end

#fetch(name) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 38

def fetch(name)
  raise ArgumentError.new("+name+ must be a String") unless name.is_a? String

  unless dependency = @dependencies.detect { |entry| entry.name == name }
    dependency = self.class::DEPENDENCY_CLASS.new(name)
    add dependency
  end

  dependency
end

#include?(dependency) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 64

def include?(dependency)
  if dependency.is_a? Dependency
    @dependencies.include? dependency
  elsif dependency.is_a? String
    @dependencies.any? { |entry| entry.name == dependency }
  else
    raise ArgumentError.new("+dependency+ must be a Doubleshot::Dependencies::Dependency or a String")
  end
end

#sizeObject Also known as: length



49
50
51
# File 'lib/doubleshot/dependencies/dependency_list.rb', line 49

def size
  @dependencies.size
end