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

#initialize(*args) ⇒ 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
    @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

#driverObject (readonly)

Returns the value of attribute driver



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

def driver
  @driver
end

#pathObject (readonly)

Returns the value of attribute path



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

def path
  @path
end

#path_cacheObject (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

#==(other) ⇒ Object



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

#created_atObject



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

def created_at; get :created_at end

#delete(*args) ⇒ Object Also known as: remove



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

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

#dir(path = nil) ⇒ Object 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

#dir?Boolean



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

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

#entry(path = nil) ⇒ Object 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

#eql?(other) ⇒ Boolean



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

#file(path = nil) ⇒ Object 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

#file?Boolean



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

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

#get(attr_name = nil) ⇒ Object

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

#hashObject



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

def hash
  driver.hash + path.hash
end

#inspectObject 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

#local?Boolean



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

def local?
  driver.local?
end

#nameObject

Miscellaneous



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

def name
  path_cache.name
end

#parentObject

Navigation



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

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

#set(options) ⇒ Object



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

def set options
  # TODO2 set attributes
  not_implemented
end

#tmp(&block) ⇒ Object



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

#updated_atObject



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

def updated_at; get :updated_at end