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.
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.
“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
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
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
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
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
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
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
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
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
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
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
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
Return the name of the package dependency.
# File lib/pom/require.rb, line 164 def name @vname.name end
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
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
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
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
Dependencies that are not optional and not alternates are considered required dependencies.
# File lib/pom/require.rb, line 203 def required? !(optional? || alternate?) end
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
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
Return the name and version contraint as a String.
# File lib/pom/require.rb, line 174 def to_s "#{name} #{version}".strip end
Generated with the Darkfish Rdoc Generator 2.