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

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
    @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



103
104
105
106
# File 'lib/vfs/entries/entry.rb', line 103

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

#created_atObject



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

def created_at; get :created_at end

#destroy(*args) ⇒ Object



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

def destroy *args; delete *args end

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

Transformations.



25
26
27
28
29
30
31
32
# File 'lib/vfs/entries/entry.rb', line 25

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

#dir?Boolean

Returns:

  • (Boolean)


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

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

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



45
46
47
48
49
50
51
52
53
54
# File 'lib/vfs/entries/entry.rb', line 45

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

Returns:

  • (Boolean)


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

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



35
36
37
38
39
40
41
42
# File 'lib/vfs/entries/entry.rb', line 35

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

#file?Boolean

Returns:

  • (Boolean)


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

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

#get(attr_name = nil) ⇒ Object

Attributes.



59
60
61
62
# File 'lib/vfs/entries/entry.rb', line 59

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

#hashObject



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

def hash
  driver.hash + path.hash
end

#inspectObject Also known as: to_s

Utils.



98
99
100
# File 'lib/vfs/entries/entry.rb', line 98

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

#local?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/vfs/entries/entry.rb', line 92

def local?
  driver.local?
end

#nameObject

Miscellaneous.



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

def name
  path_cache.name
end

#parentObject

Navigation.



19
20
21
# File 'lib/vfs/entries/entry.rb', line 19

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

#remove(*args) ⇒ Object



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

def remove *args; delete *args end

#set(options) ⇒ Object



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

def set options
  # TODO2 set attributes
  not_implemented
end

#tmp(&block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vfs/entries/entry.rb', line 80

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



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

def updated_at; get :updated_at end