Class: Teapot::Package
- Inherits:
-
Object
- Object
- Teapot::Package
- Defined in:
- lib/teapot/package.rb
Overview
A package in the dependency graph.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Packages are considered equal if they have the same path.
-
#external? ⇒ Boolean
Whether this package should be cloned from an external source repository.
-
#external_url(root_path = nil) ⇒ Object
Construct the full URL from which this package should be cloned, combining the root path, source URI, and package URI.
-
#freeze ⇒ Object
Make the package immutable to prevent modification after it’s been loaded and processed.
-
#hash ⇒ Object
Packages are hashed by path for use as hash keys and set members.
-
#initialize(path, name, options = {}) ⇒ Package
constructor
Initialize a new package.
-
#local ⇒ Object
The local filesystem path if this package is linked rather than cloned.
-
#local? ⇒ Boolean
Whether this package is linked from a local path instead of being cloned from a remote repository.
-
#source_uri ⇒ Object
The source uri from which this package would be cloned.
- #to_s ⇒ Object
Constructor Details
#initialize(path, name, options = {}) ⇒ Package
Initialize a new package.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/teapot/package.rb', line 20 def initialize(path, name, = {}) # 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 [:name] @name = [: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 = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
53 54 55 |
# File 'lib/teapot/package.rb', line 53 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
57 58 59 |
# File 'lib/teapot/package.rb', line 57 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
54 55 56 |
# File 'lib/teapot/package.rb', line 54 def path @path end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
56 57 58 |
# File 'lib/teapot/package.rb', line 56 def uri @uri end |
Instance Method Details
#eql?(other) ⇒ Boolean
Packages are considered equal if they have the same path.
111 112 113 |
# File 'lib/teapot/package.rb', line 111 def eql?(other) @path.eql?(other.path) end |
#external? ⇒ Boolean
Whether this package should be cloned from an external source repository.
73 74 75 |
# File 'lib/teapot/package.rb', line 73 def external? @options.include?(:source) end |
#external_url(root_path = nil) ⇒ Object
Construct the full URL from which this package should be cloned, combining the root path, source URI, and package URI.
85 86 87 |
# File 'lib/teapot/package.rb', line 85 def external_url(root_path = nil) Build::URI[root_path] + source_uri + Build::URI[@uri] end |
#freeze ⇒ Object
Make the package immutable to prevent modification after it’s been loaded and processed.
44 45 46 47 48 49 50 51 |
# File 'lib/teapot/package.rb', line 44 def freeze @path.freeze @name.freeze @uri.freeze @options.freeze super end |
#hash ⇒ Object
Packages are hashed by path for use as hash keys and set members.
104 105 106 |
# File 'lib/teapot/package.rb', line 104 def hash @path.hash end |
#local ⇒ Object
The local filesystem path if this package is linked rather than cloned.
61 62 63 |
# File 'lib/teapot/package.rb', line 61 def local @options[:local].to_s end |
#local? ⇒ Boolean
Whether this package is linked from a local path instead of being cloned from a remote repository.
67 68 69 |
# File 'lib/teapot/package.rb', line 67 def local? @options.include?(:local) end |
#source_uri ⇒ Object
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.
78 79 80 |
# File 'lib/teapot/package.rb', line 78 def source_uri Build::URI[@options[:source]] end |
#to_s ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/teapot/package.rb', line 90 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 |