class Mhc::WebDav::Cache
Public Class Methods
new(top_directory)
click to toggle source
# File lib/mhc/webdav.rb, line 205 def initialize(top_directory) set_top_directory(top_directory) end
Public Instance Methods
copy(src_path, dest_path)
click to toggle source
8.8 COPY
# File lib/mhc/webdav.rb, line 271 def copy(src_path, dest_path) raise NotImplementedError end
delete(path)
click to toggle source
8.6 DELETE
# File lib/mhc/webdav.rb, line 257 def delete(path) File.unlink(local_path(path)) end
get(path)
click to toggle source
8.4 GET
# File lib/mhc/webdav.rb, line 242 def get(path) File.read(local_path(path)) end
head(path)
click to toggle source
8.4 HEAD
# File lib/mhc/webdav.rb, line 247 def head(path) raise NotImplementedError end
lock(path)
click to toggle source
8.10 LOCK
# File lib/mhc/webdav.rb, line 281 def lock(path) raise NotImplementedError end
mkcol(path)
click to toggle source
8.3 MKCOL
# File lib/mhc/webdav.rb, line 237 def mkcol(path) File.mkdir(local_path(path)) end
move(src_path, dest_path)
click to toggle source
8.9 MOVE
# File lib/mhc/webdav.rb, line 276 def move(src_path, dest_path) raise NotImplementedError end
post(content, dest_path)
click to toggle source
8.5 POST
# File lib/mhc/webdav.rb, line 252 def post(content, dest_path) raise NotImplementedError end
propfind(path, depth = 1, xml_body = nil)
click to toggle source
8.1 PROPFIND
# File lib/mhc/webdav.rb, line 227 def propfind(path, depth = 1, xml_body = nil) File.read(local_cache_path(path)) rescue nil end
proppatch()
click to toggle source
8.2 PROPPATCH
# File lib/mhc/webdav.rb, line 232 def proppatch raise NotImplementedError end
put(content, dest_path)
click to toggle source
8.7 PUT
# File lib/mhc/webdav.rb, line 262 def put(content, dest_path) make_directory_or_higher(File.dirname(local_path(dest_path))) File.open(local_path(dest_path), "w") do |f| f.write(content) end end
set_basic_auth(user, password)
click to toggle source
# File lib/mhc/webdav.rb, line 221 def set_basic_auth(user, password) # nothing to do return self end
set_propfind_cache(path, xml)
click to toggle source
# File lib/mhc/webdav.rb, line 215 def set_propfind_cache(path, xml) File.open(local_cache_path(path), "w") do |f| f.write(xml) end end
set_top_directory(path)
click to toggle source
# File lib/mhc/webdav.rb, line 209 def set_top_directory(path) raise DirectoryNotFoundError unless File.directory?(path) @local_top_pathname = Pathname.new(path) return self end
unlock(path)
click to toggle source
8.11 UNLOCK
# File lib/mhc/webdav.rb, line 286 def unlock(path) raise NotImplementedError end
Private Instance Methods
local_cache_path(path)
click to toggle source
# File lib/mhc/webdav.rb, line 311 def local_cache_path(path) if File.directory?(local_path(path)) (local_pathname(path) + "propfind-cache.xml").cleanpath.to_s else local_path(path) end end
local_path(path)
click to toggle source
# File lib/mhc/webdav.rb, line 307 def local_path(path) local_pathname(path).to_s end
local_pathname(path)
click to toggle source
# File lib/mhc/webdav.rb, line 301 def local_pathname(path) pathname = Pathname.new(path) raise "path (#{path.to_s})should be absolute." unless pathname.absolute? (@local_top_pathname + ("./" + pathname)).cleanpath end
make_directory_or_higher(directory)
click to toggle source
# File lib/mhc/webdav.rb, line 292 def make_directory_or_higher(directory) unless File.directory?(directory) parent = File.dirname(directory) make_directory_or_higher(parent) print "mkdir #{directory}\n" return Dir.mkdir(directory) end end