Class: Vfs::Entry
- Inherits:
-
Object
show all
- Defined in:
- lib/vfs/entries/entry.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Entry
Returns a new instance of Entry.
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/vfs/entries/entry.rb', line 5
def initialize *args
if args.size == 1 and args.first.is_a? Entry
entry = args.first
@path_cache = entry.path_cache
@storage, @path = entry.storage, entry.path
else
storage, path = *args
@path_cache = Path.new path
@storage, @path = storage, path_cache.to_s
end
raise "storage not defined!" unless self.storage
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
3
4
5
|
# File 'lib/vfs/entries/entry.rb', line 3
def path
@path
end
|
#path_cache ⇒ Object
Returns the value of attribute path_cache.
3
4
5
|
# File 'lib/vfs/entries/entry.rb', line 3
def path_cache
@path_cache
end
|
#storage ⇒ Object
Returns the value of attribute storage.
3
4
5
|
# File 'lib/vfs/entries/entry.rb', line 3
def storage
@storage
end
|
Instance Method Details
#==(other) ⇒ Object
115
116
117
118
|
# File 'lib/vfs/entries/entry.rb', line 115
def == other
return false unless other.is_a? Entry
storage == other.storage and path == other.path
end
|
#created_at ⇒ Object
79
|
# File 'lib/vfs/entries/entry.rb', line 79
def created_at; get :created_at end
|
#dir(path = nil) ⇒ Object
Also known as:
to_dir
30
31
32
33
34
35
36
37
|
# File 'lib/vfs/entries/entry.rb', line 30
def dir path = nil
if path
new_path = path_cache + path
Dir.new storage, new_path
else
Dir.new self
end
end
|
#dir? ⇒ Boolean
77
|
# File 'lib/vfs/entries/entry.rb', line 77
def dir?; !!get(:dir) end
|
#entry(path = nil) ⇒ Object
Also known as:
to_entry
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/vfs/entries/entry.rb', line 50
def entry path = nil
entry = if path
new_path = path_cache + path
klass = new_path.probably_dir? ? Dir : UniversalEntry
entry = klass.new storage, new_path
else
UniversalEntry.new self
end
EntryProxy.new entry
end
|
#eql?(other) ⇒ Boolean
124
125
126
127
|
# File 'lib/vfs/entries/entry.rb', line 124
def eql? other
return false unless other.class == self.class
storage.eql?(other.storage) and path.eql?(other.path)
end
|
#file(path = nil) ⇒ Object
Also known as:
to_file
40
41
42
43
44
45
46
47
|
# File 'lib/vfs/entries/entry.rb', line 40
def file path = nil
if path
new_path = path_cache + path
File.new storage, new_path
else
File.new self
end
end
|
#file? ⇒ Boolean
78
|
# File 'lib/vfs/entries/entry.rb', line 78
def file?; !!get(:file) end
|
#get(attr_name = nil) ⇒ Object
67
68
69
70
|
# File 'lib/vfs/entries/entry.rb', line 67
def get attr_name = nil
attrs = storage.open{|fs| fs.attributes(path)}
(attr_name and attrs) ? attrs[attr_name] : attrs
end
|
#hash ⇒ Object
120
121
122
|
# File 'lib/vfs/entries/entry.rb', line 120
def hash
storage.hash + path.hash
end
|
#inspect ⇒ Object
Also known as:
to_s
110
111
112
|
# File 'lib/vfs/entries/entry.rb', line 110
def inspect
"#{storage}#{':' unless storage.to_s.empty?}#{path}"
end
|
#local? ⇒ Boolean
102
103
104
|
# File 'lib/vfs/entries/entry.rb', line 102
def local?
storage.local?
end
|
#name ⇒ Object
86
87
88
|
# File 'lib/vfs/entries/entry.rb', line 86
def name
path_cache.name
end
|
#parent ⇒ Object
22
23
24
|
# File 'lib/vfs/entries/entry.rb', line 22
def parent
Dir.new(storage, path_cache + '..')
end
|
#set(options) ⇒ Object
72
73
74
75
|
# File 'lib/vfs/entries/entry.rb', line 72
def set options
not_implemented
end
|
#tmp(&block) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/vfs/entries/entry.rb', line 90
def tmp &block
storage.open do |fs|
if block
fs.tmp do |path|
block.call Dir.new(storage, path)
end
else
Dir.new storage, fs.tmp
end
end
end
|
#updated_at ⇒ Object
80
|
# File 'lib/vfs/entries/entry.rb', line 80
def updated_at; get :updated_at end
|