Parent

Namespace

Files

POM::Dependency

The Dependecny class models a single project dependency, consisting of the requirement’s name, version constraint and categorical grouping.

TODO: In the future, dependencies may need to by SCM repositories URIs, rather than simply package names.

Attributes

environment[R]

The first portion of the group is called the dependency’s environment.

group[R]

Categorical group to which the requirement belongs.

package[R]

The package name and contraint. This is kept as a single string, but under-the-hood is converted into a VName object, which handles the name a version contraints separately.

subset[R]

The second portion of the group is called the dependency’s subset.

Public Class Methods

new(package, group='runtime') click to toggle source

New dependency object.

# File lib/pom/require.rb, line 144
def initialize(package, group='runtime')
  self.package = package
  self.group   = group.to_s
end

Public Instance Methods

<=>(other) click to toggle source

“Spaceship” comparision. Returns 0 if two dependencies are equal. Otherwise it compares their version contraints.

# File lib/pom/require.rb, line 318
def <=>(other)
  return 0 if self == other
  constraint <=> other.constraint
end
==(other) click to toggle source

Compare dependencies for equality. Two depencies are equal if they have the same name and teh same constraint.

# File lib/pom/require.rb, line 297
def ==(other)
  return false unless Dependency === other
  #return false unless group == other.group
  return false unless name == other.name
  return false unless constraint == other.constraint
  return true
end
alternate?() click to toggle source

A dependency is an *alternate dependency* if its environment is set to `alternate`. Alternate dependencies specify other packages that can be used in exchange or cannot be used in conjunction with the present package. They are not intended to have any (or at least much) functional effect, but serve mosty to as a useful source of information about the relationship between pacakges and their use of specifications.

# File lib/pom/require.rb, line 236
def alternate?
  environment == 'alternate'
end
alternative?() click to toggle source

An alternative is a package that the present package can fulfill the same basic API (more or less). For example the ‘rdiscount’ gem can effectively provide the same functionality as the ‘BlueCloth’ gem.

# File lib/pom/require.rb, line 243
def alternative?
  alternate? && subset.empty?
end
conflict?() click to toggle source

An conflict is a “dependency” (if we make take the liberty to call it as much) identified by subset labeled `conflict`. A package is in conflict with the present package when it will effectively break the operation of the present package.

# File lib/pom/require.rb, line 260
def conflict?
  alternate? && subset == 'conflict'
end
constraint() click to toggle source

Converts the version into a constraint recognizable by RubyGems. POM recognizes suffixed constraints as well as prefixed constraints. This method converts suffixed constraints to prefixed constraints.

POM::Dependency.new('foo 1.0+').constraint
#=> ">= 1.0"

May I just comment that Ruby could really use a real Interval class with proper support for infinity.

# File lib/pom/require.rb, line 282
def constraint
  case version
  when /^(.*?)\~$/
    "~> #{$1}"
  when /^(.*?)\+$/
    ">= #{$1}"
  when /^(.*?)\-$/
    "< #{$1}"
  else
    version
  end
end
development?() click to toggle source

A dependency is a development dependency if its environment is set to ‘development’.

# File lib/pom/require.rb, line 209
def development?
  environment == 'development' #or environment == 'dev'
end
document?() click to toggle source

A dependency is a *test dependecny* if it is a development dependency with a subet set to `document`.

# File lib/pom/require.rb, line 221
def document?
  development? && subset == 'document'
end
eql?() click to toggle source

Compare dependencies for unique equality. Two depencies are not unique if they have the same group, name and constraint.

# File lib/pom/require.rb, line 307
def eql?
  return false unless Dependency === other
  return false unless group == other.group
  return false unless name == other.name
  return false unless constraint == other.constraint
  return true
end
group=(group) click to toggle source

Set the categorical group. At the same time, parse the goup into environment and subset values.

# File lib/pom/require.rb, line 158
def group=(group)
  @group = group
  @environment, @subset = group.split(/\//)
end
hash() click to toggle source

Identifying hash, essentially the number characterizes the nature of eql?

TODO: how best to define?

# File lib/pom/require.rb, line 327
def hash
  h = 0
  h ^= group.hash
  h *=137
  h ^= name.hash
  h *=137
  h ^= constraint.hash
  h
end
inspect() click to toggle source

Same as to_S, returning the name and version contraint as a String.

# File lib/pom/require.rb, line 180
def inspect
  "#{name} #{version}".strip
end
name() click to toggle source

Return the name of the package dependency.

# File lib/pom/require.rb, line 164
def name
  @vname.name
end
optional?() click to toggle source

Is thie an optional dependency? All development dependencies and specifcally marked runtime dependencies are considered optional.

# File lib/pom/require.rb, line 197
def optional?
  development? || (runtime? && subset == 'optional')
end
package=(package) click to toggle source

Set the package. This translates the package setting into a VName object at the same time.

# File lib/pom/require.rb, line 151
def package=(package)
  @package = package
  @vname = VName.new(package)
end
production?() click to toggle source

Alias for runtime?

Alias for: runtime?
provision?() click to toggle source

An provision is a dependency, identified by a subset labeled `provision`. A provsion is an arbitrary term that succinctly describes the functionaltiy of the present package. For example the `rdiscount` gem can be said to provide `markdown` support and may even specify a limiting version of that specification.

# File lib/pom/require.rb, line 269
def provision?
  alternate? && subset == 'provision'
end
replacement?() click to toggle source

A replacement is an alternate dependency identifies by a subset set to `replacement`. The setting asks, what other packages does this package replace? This is very much like a regular alternative but expresses a overriding relation. For instance “libXML” has been replaced by “libXML2” –and the API might not be compatibile at all.

# File lib/pom/require.rb, line 252
def replacement?
  alternate? && subset == 'replacement'
end
required?() click to toggle source

Dependencies that are not optional and not alternates are considered required dependencies.

# File lib/pom/require.rb, line 203
def required?
  !(optional? || alternate?)
end
runtime?() click to toggle source

Is this dependency a runtime dependency? This means it is need for the project to operate, or at least operate for specific capacities.

# File lib/pom/require.rb, line 187
def runtime?
  environment == 'runtime' || environment == 'production'
end
Also aliased as: production?
test?() click to toggle source

A dependency is a *test dependecny* if it is a development dependency with a subet set to `test`.

# File lib/pom/require.rb, line 215
def test?
  development? && subset == 'test'
end
to_s() click to toggle source

Return the name and version contraint as a String.

# File lib/pom/require.rb, line 174
def to_s
  "#{name} #{version}".strip
end
vendored?() click to toggle source
# File lib/pom/require.rb, line 226
def vendored?
  subset == 'vendor'
end
version() click to toggle source

Return the verion constraint of the package dependency.

# File lib/pom/require.rb, line 169
def version
  @vname.version
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.