lib/imw/resource.rb in imw-0.2.6 vs lib/imw/resource.rb in imw-0.2.7
- old
+ new
@@ -72,12 +72,19 @@
#
# You can also instantiate an IMW::Resource using IMW.open, which
# accepts all the same arguments as IMW::Resource.new.
class Resource
- attr_reader :uri, :mode
+ # The URI object associated with this resource.
+ attr_reader :uri
+ # The mode in which to access this resource.
+ attr_accessor :mode
+
+ # A copy of the options passed to this resource on initialization.
+ attr_accessor :resource_options
+
# Create a new resource representing +uri+.
#
# IMW will automatically extend the resulting IMW::Resourcen
# instance with modules appropriate to the given URI.
#
@@ -100,12 +107,13 @@
# @param [Hash] options
# @option options [true, false] no_modules
# @option options [String] mode the mode to open the resource in (will be ignored when inapplicable)
# @return [IMW::Resource]
def initialize uri, options={}
- self.uri = uri
- @mode = options[:mode] || 'r'
+ self.uri = uri
+ self.resource_options = options
+ self.mode = options[:mode] || 'r'
extend_appropriately!(options) unless options[:no_modules]
end
# Return the modules this resource has been extended by.
#
@@ -188,9 +196,16 @@
# IMW.open('/path/to/some_file.tar.gz').name # => some_file
#
# @return [String]
def name
@name ||= extname ? basename[0,basename.length - extname.length] : basename
+ end
+
+ # Returns the user associated with the host of this URI.
+ #
+ # @return [String]
+ def user
+ @user ||= uri.user
end
def to_s
uri.to_s
end