Class: Vfs::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/vfs/entries/entry.rb

Direct Known Subclasses

Dir, File, UniversalEntry

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Entry) initialize(*args)



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
    @driver, @path = entry.driver, entry.path
  else
    driver, path = *args
    @path_cache = Path.new path
    @driver, @path = driver, path_cache.to_s
  end
  raise "driver not defined!" unless self.driver
end

Instance Attribute Details

- (Object) driver (readonly)

Returns the value of attribute driver



3
4
5
# File 'lib/vfs/entries/entry.rb', line 3

def driver
  @driver
end

- (Object) path (readonly)

Returns the value of attribute path



3
4
5
# File 'lib/vfs/entries/entry.rb', line 3

def path
  @path
end

- (Object) path_cache (readonly)

Returns the value of attribute path_cache



3
4
5
# File 'lib/vfs/entries/entry.rb', line 3

def path_cache
  @path_cache
end

Instance Method Details

- (Object) ==(other)



113
114
115
116
# File 'lib/vfs/entries/entry.rb', line 113

def == other
  return false unless other.is_a? Entry
  driver == other.driver and path == other.path
end

- (Object) created_at



77
# File 'lib/vfs/entries/entry.rb', line 77

def created_at; get :created_at end

- (Object) delete(*args) Also known as: remove



127
128
129
# File 'lib/vfs/entries/entry.rb', line 127

def delete *args
  raise "use :destroy!"
end

- (Object) dir(path = nil) Also known as: to_dir

Transformations



29
30
31
32
33
34
35
36
# File 'lib/vfs/entries/entry.rb', line 29

def dir path = nil
  if path
    new_path = path_cache + path
    Dir.new driver, new_path
  else
    Dir.new self
  end
end

- (Boolean) dir?



75
# File 'lib/vfs/entries/entry.rb', line 75

def dir?; !!get(:dir) end

- (Object) entry(path = nil) Also known as: to_entry



49
50
51
52
53
54
55
56
57
58
# File 'lib/vfs/entries/entry.rb', line 49

def entry path = nil
  entry = if path
    new_path = path_cache + path
    klass = new_path.probably_dir? ? Dir : UniversalEntry
    klass.new driver, new_path
  else
    UniversalEntry.new self
  end
  EntryProxy.new entry
end

- (Boolean) eql?(other)



122
123
124
125
# File 'lib/vfs/entries/entry.rb', line 122

def eql? other
  return false unless other.class == self.class
  driver.eql?(other.driver) and path.eql?(other.path)
end

- (Object) file(path = nil) Also known as: to_file



39
40
41
42
43
44
45
46
# File 'lib/vfs/entries/entry.rb', line 39

def file path = nil
  if path
    new_path = path_cache + path
    File.new driver, new_path
  else
    File.new self
  end
end

- (Boolean) file?



76
# File 'lib/vfs/entries/entry.rb', line 76

def file?; !!get(:file) end

- (Object) get(attr_name = nil)

Attributes



65
66
67
68
# File 'lib/vfs/entries/entry.rb', line 65

def get attr_name = nil
  attrs = driver.open{driver.attributes(path)}
  (attr_name and attrs) ? attrs[attr_name] : attrs
end

- (Object) hash



118
119
120
# File 'lib/vfs/entries/entry.rb', line 118

def hash
  driver.hash + path.hash
end

- (Object) inspect Also known as: to_s

Utils



108
109
110
# File 'lib/vfs/entries/entry.rb', line 108

def inspect
  "#{driver}#{':' unless driver.to_s.empty?}#{path}"
end

- (Boolean) local?



100
101
102
# File 'lib/vfs/entries/entry.rb', line 100

def local?
  driver.local?
end

- (Object) name

Miscellaneous



84
85
86
# File 'lib/vfs/entries/entry.rb', line 84

def name
  path_cache.name
end

- (Object) parent

Navigation



21
22
23
# File 'lib/vfs/entries/entry.rb', line 21

def parent
  Dir.new(driver, path_cache.parent)
end

- (Object) set(options)



70
71
72
73
# File 'lib/vfs/entries/entry.rb', line 70

def set options
  # TODO2 set attributes
  not_implemented
end

- (Object) tmp(&block)



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/vfs/entries/entry.rb', line 88

def tmp &block
  driver.open do
    if block
      driver.tmp do |path|
        block.call Dir.new(driver, path)
      end
    else
      Dir.new driver, driver.tmp
    end
  end
end

- (Object) updated_at



78
# File 'lib/vfs/entries/entry.rb', line 78

def updated_at; get :updated_at end