class Package
A package in the dependency graph.
Definitions
def initialize(path, name, options = {})
Initialize a new package.
Signature
-
parameter
pathString The package path.
-
parameter
nameString | Symbol The package name or URI.
-
parameter
optionsHash Additional options.
Implementation
def initialize(path, name, options = {})
# The path where the package is (or will be) located:
@path = Path[path]
# Get the name of the package from the options, if provided:
if options[:name]
@name = options[:name]
end
if Symbol === name
# If the name argument was symbolic, we convert it into a string, and use it for both the uri and the name itself:
@uri = name.to_s
@name ||= @uri
else
# Otherwise, we assume a path may have been given, and use that instead:
@name ||= File.basename(name)
@uri = name
end
# Copy the options provided:
@options = options
end
def freeze
Make the package immutable to prevent modification after it's been loaded and processed.
Implementation
def freeze
@path.freeze
@name.freeze
@uri.freeze
@options.freeze
super
end
def local
The local filesystem path if this package is linked rather than cloned.
Signature
-
returns
String The local path.
Implementation
def local
@options[:local].to_s
end
def local?
Whether this package is linked from a local path instead of being cloned from a remote repository.
Signature
-
returns
Boolean True if local.
Implementation
def local?
@options.include?(:local)
end
def external?
Whether this package should be cloned from an external source repository.
Signature
-
returns
Boolean True if external.
Implementation
def external?
@options.include?(:source)
end
def source_uri
The source uri from which this package would be cloned. Might be relative, in which case it's relative to the root of the context.
Implementation
def source_uri
Build::URI[@options[:source]]
end
def external_url(root_path = nil)
Construct the full URL from which this package should be cloned, combining the root path, source URI, and package URI.
Signature
-
parameter
root_pathString | Nil The root path.
-
returns
Build::URI The external URL.
Implementation
def external_url(root_path = nil)
Build::URI[root_path] + source_uri + Build::URI[@uri]
end
def to_s
Signature
-
returns
String The string representation.
Implementation
def to_s
if self.local?
"links #{@name} from #{self.local}"
elsif self.external?
"clones #{@name} from #{self.external_url}"
else
"references #{@name} from #{@path}"
end
end
def hash
Packages are hashed by path for use as hash keys and set members.
Signature
-
returns
Integer The hash code.
Implementation
def hash
@path.hash
end
def eql?(other)
Packages are considered equal if they have the same path.
Signature
-
parameter
otherPackage The other package.
-
returns
Boolean True if equal.
Implementation
def eql?(other)
@path.eql?(other.path)
end