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

Instance Method Summary collapse

Instance Attribute Details

#uriObject

The URI of this object.



10
11
12
# File 'lib/imw/utils/has_uri.rb', line 10

def uri
  @uri
end

Instance Method Details

#basenameString

The basename of this resource’s path.

Returns:



46
47
48
# File 'lib/imw/utils/has_uri.rb', line 46

def basename
  @basename ||= File.basename(path)
end

#dirnameString

The directory name of this resource’s path.

Returns:



39
40
41
# File 'lib/imw/utils/has_uri.rb', line 39

def dirname
  @dirname  ||= File.dirname(path)
end

#extensionString

Returns the extension (WITHOUT the ‘.’) of this resource’s path.

Returns:



62
63
64
# File 'lib/imw/utils/has_uri.rb', line 62

def extension
  @extension ||= extname[1..-1] || ''
end

#extnameString

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…)

Returns:



55
56
57
# File 'lib/imw/utils/has_uri.rb', line 55

def extname
  @extname ||= File.extname(path)
end

#fragmentString

Return the fragment part of this resource’s URI.

Will likely be nil for local resources.

Returns:



94
95
96
# File 'lib/imw/utils/has_uri.rb', line 94

def fragment
  @fragment ||= uri.fragment
end

#nameString

Returns the basename of the file with its extension removed

IMW.open('/path/to/some_file.tar.gz').name # => some_file

Returns:



71
72
73
# File 'lib/imw/utils/has_uri.rb', line 71

def name
  @name ||= extname ? basename[0,basename.length - extname.length] : basename
end

#passwordString

Returns the password associated with access to this URI.

Returns:



85
86
87
# File 'lib/imw/utils/has_uri.rb', line 85

def password
  @password ||= uri.password
end

#schemeString

The scheme of this resource. Will be nil for local resources.

Returns:



32
33
34
# File 'lib/imw/utils/has_uri.rb', line 32

def scheme
  @scheme ||= uri.scheme
end

#stripped_uriURI::Generic

Return the URI of this resource with any query strings and fragments removed.

Returns:

  • (URI::Generic)


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_sObject



111
112
113
# File 'lib/imw/utils/has_uri.rb', line 111

def to_s
  uri.to_s
end

#userString

Returns the user associated with the host of this URI.

Returns:



78
79
80
# File 'lib/imw/utils/has_uri.rb', line 78

def user
  @user ||= uri.user
end