Class: DistributedStat
Constant Summary
DistributedShelf::VERSION
Instance Method Summary
collapse
#absolutepath, config=, #distributed?, #override_class_method, #proxy_method, #server_url
Constructor Details
Returns a new instance of DistributedStat.
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/dshelf/stat.rb', line 10
def initialize filename
@dpath = filename
RestClient.get("#{server_url}/stat#{URI.escape absolutepath}", {:accept => :json}) do |response, request, result|
case response.code
when 200
parse_stat response
when 404
raise Errno::ENOENT, absolutepath
end
end
end
|
Instance Method Details
#<=>(stat) ⇒ Object
59
60
61
|
# File 'lib/dshelf/stat.rb', line 59
def <=> stat
mtime <=> stat.mtime
end
|
#atime ⇒ Object
47
48
49
|
# File 'lib/dshelf/stat.rb', line 47
def atime
@dstat[:atime]
end
|
#ctime ⇒ Object
51
52
53
|
# File 'lib/dshelf/stat.rb', line 51
def ctime
@dstat[:ctime]
end
|
#directory? ⇒ Boolean
79
80
81
|
# File 'lib/dshelf/stat.rb', line 79
def directory?
@dstat[:is_dir]
end
|
#file? ⇒ Boolean
75
76
77
|
# File 'lib/dshelf/stat.rb', line 75
def file?
@dstat[:is_regular]
end
|
#ftype ⇒ Object
87
88
89
90
91
|
# File 'lib/dshelf/stat.rb', line 87
def ftype
return 'link' if symlink?
return 'directory' if directory?
'file'
end
|
#mtime ⇒ Object
55
56
57
|
# File 'lib/dshelf/stat.rb', line 55
def mtime
@dstat[:mtime]
end
|
#parse_stat(stat) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/dshelf/stat.rb', line 22
def parse_stat stat
parsed = JSON.parse stat
@dstat = {}
@dstat[:size] = parsed['size']
@dstat[:readable] = !parsed['access'].match(/read/).nil?
@dstat[:writable] = !parsed['access'].match(/write/).nil?
@dstat[:atime] = Time.parse parsed['atime']
@dstat[:ctime] = Time.parse parsed['ctime']
@dstat[:mtime] = Time.parse parsed['mtime']
@dstat[:is_file] = parsed['is_file']
@dstat[:is_dir] = parsed['is_dir']
@dstat[:is_regular] = parsed['is_regular']
end
|
#path ⇒ Object
6
7
8
|
# File 'lib/dshelf/stat.rb', line 6
def path
@dpath
end
|
#setgid? ⇒ Boolean
36
|
# File 'lib/dshelf/stat.rb', line 36
def setgid?; true end
|
#setuid? ⇒ Boolean
37
|
# File 'lib/dshelf/stat.rb', line 37
def setuid?; true end
|
#size ⇒ Object
39
40
41
|
# File 'lib/dshelf/stat.rb', line 39
def size
@dstat[:size]
end
|
#symlink? ⇒ Boolean
83
84
85
|
# File 'lib/dshelf/stat.rb', line 83
def symlink?
not @dstat[:is_file]
end
|
#zero? ⇒ Boolean
43
44
45
|
# File 'lib/dshelf/stat.rb', line 43
def zero?
size == 0
end
|