Class: Inventory::Dependencies

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/inventory-1.0/dependencies.rb

Overview

Contains zero or more dependencies of the project. Dependencies can be added, #required, enumerated, and added to Gem specifications. Dependencies are set up by passing a block to #initialize and calling #development, #runtime, and #optional inside it.

Examples:

Creating a List of Dependencies

Dependencies.new{
  development 'inventory-rake', 1, 3, 0
  runtime 'bar', 1, 6, 0
}

Defined Under Namespace

Classes: Development, Optional, Runtime

Instance Method Summary collapse

Constructor Details

#initialize(*dependencies) {|?| ... } ⇒ Dependencies

Creates a new list of DEPENDENCIES and allows more to be added in the optionally #instance_exec’d block by calling #development, #runtime, and #optional inside it.

Parameters:

Yields:

  • (?)


23
24
25
26
# File 'lib/inventory-1.0/dependencies.rb', line 23

def initialize(*dependencies)
  @dependencies = dependencies
  instance_exec(&Proc.new) if block_given?
end

Instance Method Details

#+(other) ⇒ Dependencies

Returns The dependencies of the receiver and those of OTHER.

Returns:

  • (Dependencies)

    The dependencies of the receiver and those of OTHER



66
67
68
# File 'lib/inventory-1.0/dependencies.rb', line 66

def +(other)
  self.class.new(*(dependencies + other.dependencies))
end

#add_to_gem_specification(specification) ⇒ self

Add each dependency to a Gem specification.

Parameters:

  • specification (Gem::Specification)

Returns:

  • (self)


95
96
97
98
99
100
# File 'lib/inventory-1.0/dependencies.rb', line 95

def add_to_gem_specification(specification)
  each do |dependency|
    dependency.add_to_gem_specification specification
  end
  self
end

# {|dependency| ... } ⇒ Object #Enumerator<Dependency>

Overloads:

  • # {|dependency| ... } ⇒ Object

    Enumerates the dependencies.

    Yield Parameters:

  • #Enumerator<Dependency>

    Returns An Enumerator over the dependencies.

    Returns:

    • (Enumerator<Dependency>)

      An Enumerator over the dependencies



76
77
78
79
80
81
82
# File 'lib/inventory-1.0/dependencies.rb', line 76

def each
  return enum_for(__method__) unless block_given?
  dependencies.each do |dependency|
    yield dependency
  end
  self
end

#requireself

Require each dependency in turn.

Returns:

  • (self)


86
87
88
89
# File 'lib/inventory-1.0/dependencies.rb', line 86

def require
  map{ |dependency| dependency.require }
  self
end