Module: IMW::Utils::HasURI
- Included in:
- Resource
- Defined in:
- lib/imw/utils/has_uri.rb
Overview
Endows an including class with a wrapper for Addressable::URI
Instance Attribute Summary collapse
-
#uri ⇒ Object
The URI of this object.
Instance Method Summary collapse
-
#basename ⇒ String
The basename of this resource’s path.
-
#dirname ⇒ String
The directory name of this resource’s path.
-
#extension ⇒ String
Returns the extension (WITHOUT the ‘.’) of this resource’s path.
-
#extname ⇒ String
Returns the extension (INCLUDING the ‘.’) of this resource’s path.
-
#fragment ⇒ String
Return the fragment part of this resource’s URI.
-
#name ⇒ String
Returns the basename of the file with its extension removed.
-
#password ⇒ String
Returns the password associated with access to this URI.
-
#scheme ⇒ String
The scheme of this resource.
-
#stripped_uri ⇒ URI::Generic
Return the URI of this resource with any query strings and fragments removed.
- #to_s ⇒ Object
-
#user ⇒ String
Returns the user associated with the host of this URI.
Instance Attribute Details
#uri ⇒ Object
The URI of this object.
10 11 12 |
# File 'lib/imw/utils/has_uri.rb', line 10 def uri @uri end |
Instance Method Details
#basename ⇒ String
The basename of this resource’s path.
46 47 48 |
# File 'lib/imw/utils/has_uri.rb', line 46 def basename @basename ||= File.basename(path) end |
#dirname ⇒ String
The directory name of this resource’s path.
39 40 41 |
# File 'lib/imw/utils/has_uri.rb', line 39 def dirname @dirname ||= File.dirname(path) end |
#extension ⇒ String
Returns the extension (WITHOUT the ‘.’) of this resource’s path.
62 63 64 |
# File 'lib/imw/utils/has_uri.rb', line 62 def extension @extension ||= extname[1..-1] || '' end |
#extname ⇒ String
Returns the extension (INCLUDING the ‘.’) of this resource’s path. Redefine this in an including class for which this is weird (‘.tar.gz’ I’m talking to you…)
55 56 57 |
# File 'lib/imw/utils/has_uri.rb', line 55 def extname @extname ||= File.extname(path) end |
#fragment ⇒ String
Return the fragment part of this resource’s URI.
Will likely be nil
for local resources.
94 95 96 |
# File 'lib/imw/utils/has_uri.rb', line 94 def fragment @fragment ||= uri.fragment end |
#name ⇒ String
71 72 73 |
# File 'lib/imw/utils/has_uri.rb', line 71 def name @name ||= extname ? basename[0,basename.length - extname.length] : basename end |
#password ⇒ String
Returns the password associated with access to this URI.
85 86 87 |
# File 'lib/imw/utils/has_uri.rb', line 85 def password @password ||= uri.password end |
#scheme ⇒ String
The scheme of this resource. Will be nil
for local resources.
32 33 34 |
# File 'lib/imw/utils/has_uri.rb', line 32 def scheme @scheme ||= uri.scheme end |
#stripped_uri ⇒ URI::Generic
Return the URI of this resource with any query strings and fragments removed.
102 103 104 105 106 107 108 109 |
# File 'lib/imw/utils/has_uri.rb', line 102 def stripped_uri uri_args = returning({}) do |args| %w[scheme userinfo host port path].each do |method| args[method.to_sym] = respond_to?(method) ? send(method) : uri.send(method) end end uri.class.new(uri_args) end |
#to_s ⇒ Object
111 112 113 |
# File 'lib/imw/utils/has_uri.rb', line 111 def to_s uri.to_s end |
#user ⇒ String
Returns the user associated with the host of this URI.
78 79 80 |
# File 'lib/imw/utils/has_uri.rb', line 78 def user @user ||= uri.user end |