Class: Teapot::Package
- Inherits:
-
Object
- Object
- Teapot::Package
- Defined in:
- lib/teapot/package.rb
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
- #external? ⇒ Boolean
- #external_url(relative_root) ⇒ Object
-
#hash ⇒ Object
Package may be used as hash key / in a set:.
-
#initialize(path, name, options = {}) ⇒ Package
constructor
A new instance of Package.
- #local? ⇒ Boolean
- #source ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path, name, options = {}) ⇒ Package
Returns a new instance of Package.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/teapot/package.rb', line 31 def initialize(path, name, = {}) # The path where the package is (or will be) located: @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.
54 55 56 |
# File 'lib/teapot/package.rb', line 54 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
58 59 60 |
# File 'lib/teapot/package.rb', line 58 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
55 56 57 |
# File 'lib/teapot/package.rb', line 55 def path @path end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
57 58 59 |
# File 'lib/teapot/package.rb', line 57 def uri @uri end |
Instance Method Details
#eql?(other) ⇒ Boolean
92 93 94 |
# File 'lib/teapot/package.rb', line 92 def eql?(other) @path.eql?(other.path) end |
#external? ⇒ Boolean
64 65 66 |
# File 'lib/teapot/package.rb', line 64 def external? @options.key? :source end |
#external_url(relative_root) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/teapot/package.rb', line 72 def external_url(relative_root) base_uri = URI(source) if base_uri.scheme == nil || base_uri.scheme == 'file' base_uri = URI "file://" + File.(base_uri.path, relative_root) + "/" end return relative_url(base_uri) end |
#hash ⇒ Object
Package may be used as hash key / in a set:
88 89 90 |
# File 'lib/teapot/package.rb', line 88 def hash @path.hash end |
#local? ⇒ Boolean
60 61 62 |
# File 'lib/teapot/package.rb', line 60 def local? @options.key? :local end |
#source ⇒ Object
68 69 70 |
# File 'lib/teapot/package.rb', line 68 def source @options[:source].to_s + '/' end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/teapot/package.rb', line 82 def to_s "<#{self.class.name} #{@name.dump} path=#{path}>" end |