Class: Vmit::VFS::URI
Class Method Summary collapse
-
.accept?(location) ⇒ Boolean
Whether this handler accepts the given location.
- .open(loc, *rest, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(location) ⇒ URI
constructor
A new instance of URI.
-
#open(loc, *rest, &block) ⇒ Object
Open a filename relative to the base location.
Methods inherited from Handler
Constructor Details
#initialize(location) ⇒ URI
Returns a new instance of URI.
64 65 66 67 68 69 |
# File 'lib/vmit/vfs.rb', line 64 def initialize(location) @base_uri = case location when ::URI then location else ::URI.parse(location.to_s) end end |
Class Method Details
.accept?(location) ⇒ Boolean
Whether this handler accepts the given location
55 56 57 58 59 60 61 |
# File 'lib/vmit/vfs.rb', line 55 def self.accept?(location) uri = case location when ::URI then location else ::URI.parse(location.to_s) end ['http', 'ftp'].include?(uri.scheme) end |
.open(loc, *rest, &block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vmit/vfs.rb', line 71 def self.open(loc, *rest, &block) uri = case loc when ::URI then loc else ::URI.parse(loc.to_s) end unless accept?(uri) raise ArgumentError.new('Only HTTP/FTP supported') end = nil @filename = File.basename(uri.path) ret = OpenURI.open_uri(uri.to_s, :content_length_proc => lambda { |t| if t && 0 < t = ProgressBar.new(@filename, t) .file_transfer_mode end }, :progress_proc => lambda { |s| .set s if }, &block) = nil # So that the progress bar line get overwriten STDOUT.print "\r" STDOUT.flush ret end |
Instance Method Details
#open(loc, *rest, &block) ⇒ Object
Open a filename relative to the base location.
103 104 105 106 107 108 |
# File 'lib/vmit/vfs.rb', line 103 def open(loc, *rest, &block) uri = @base_uri.clone uri.path = File.join(uri.path, loc.to_s) Vmit::VFS::URI.open(uri, *rest, &block) end |