Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/open-uri-and-write/file_extensions.rb

Overview

Extensions and modifications (monkeypatching) to the File class:

Class Method Summary collapse

Class Method Details

.delete(names) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/open-uri-and-write/file_extensions.rb', line 20

def self.delete(names)
  filenames = []
  if(names.class == String)
    filenames << names
  elsif(names.class = Array)
    filenames = names
  end
  filenames.each do |filename|
    if(filename[/^(https?):\/\//])
      dav = OpenUriAndWrite::CredentialsStore.get_connection_for_url(filename)
      dav.delete(filename)
    else
      self.original_delete(filename)
    end
  end
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
# File 'lib/open-uri-and-write/file_extensions.rb', line 11

def self.exists?(name)
  if(name[/https?:\/\//])
    dav = OpenUriAndWrite::CredentialsStore.get_connection_for_url(name)
    dav.exists?(name)
  else
    self.original_exists?(name)
  end
end

.open(name, *rest, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/open-uri-and-write/file_extensions.rb', line 37

def self.open(name, *rest, &block)
  if name.respond_to?(:open)
    name.open(*rest, &block)
  elsif name.respond_to?(:to_s) and name[/^(https?):\/\//] and rest.size > 0 and rest.first.to_s[/^w/]
    webdav_agent = OpenUriAndWrite::Handle.new(name, rest)
    if(block)
      yield webdav_agent
    else
      return webdav_agent
    end
  else
    self.original_open(name, *rest, &block)
  end
end

.original_deleteObject



6
# File 'lib/open-uri-and-write/file_extensions.rb', line 6

alias original_delete delete

.original_exists?Object



8
# File 'lib/open-uri-and-write/file_extensions.rb', line 8

alias original_exists? exists?

.original_openObject



7
# File 'lib/open-uri-and-write/file_extensions.rb', line 7

alias original_open open