Class: FakeFS::File::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/fakefs/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, __lstat = false) ⇒ Stat

Returns a new instance of Stat.



210
211
212
213
214
215
216
217
# File 'lib/fakefs/file.rb', line 210

def initialize(file, __lstat = false)
  if !File.exists?(file)
    raise(Errno::ENOENT, "No such file or directory - #{file}")
  end

  @file    = file
  @__lstat = __lstat
end

Instance Method Details

#directory?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/fakefs/file.rb', line 223

def directory?
  File.directory?(@file)
end


227
228
229
# File 'lib/fakefs/file.rb', line 227

def nlink
  FileSystem.find(@file).links.size
end

#sizeObject



231
232
233
234
235
236
237
# File 'lib/fakefs/file.rb', line 231

def size
  if @__lstat && symlink?
    FileSystem.find(@file).target.size
  else
    File.size(@file)
  end
end

#symlink?Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/fakefs/file.rb', line 219

def symlink?
  File.symlink?(@file)
end