Sha256: 3676abf849a2ddf9d749fbcaff5b42f854c35268939e7e1f68bd6f6fc6b0f774
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require 'imw/utils/has_uri' module IMW class Resource attr_accessor :mode, :resource_options def initialize uri, options={} self.uri = uri self.resource_options = options self.mode = options[:mode] || 'r' extend_appropriately!(options) end # Provides resources with a wrapped Addressable::URI object. include IMW::Utils::HasURI # Gives IMW::Resource instances with the ability to dynamically # extend themselves with modules chosen from a set of handlers # stored by the IMW::Resource class. include IMW::Utils::DynamicallyExtendable [IMW::Schemes::HANDLERS, IMW::Formats::HANDLERS].each do |handlers| register_handlers *handlers end def should_exist!(message=nil) raise IMW::Error.new([message, "No path defined for #{self.inspect} extended by #{modules.join(' ')}"].compact.join(', ')) unless respond_to?(:path) raise IMW::Error.new([message, "No exist? method defined for #{self.inspect} extended by #{modules.join(' ')}"].compact.join(', ')) unless respond_to?(:exist?) raise IMW::PathError.new([message, "#{path} does not exist"].compact.join(', ')) unless exist? self end def close end def reopen IMW.open(uri.to_s) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
imw-0.3.0 | lib/imw/resource.rb |