Class: Microsandbox::FsEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/microsandbox/fs.rb

Overview

A directory entry returned by Microsandbox::FS#list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ FsEntry

Returns a new instance of FsEntry.



15
16
17
18
19
20
21
# File 'lib/microsandbox/fs.rb', line 15

def initialize(data)
  @path = data["path"]
  @type = data["type"].to_sym
  @size = data["size"]
  @mode = data["mode"]
  @modified_ms = data["modified_ms"]
end

Instance Attribute Details

#modeInteger (readonly)

Returns POSIX mode bits.

Returns:

  • (Integer)

    POSIX mode bits



13
14
15
# File 'lib/microsandbox/fs.rb', line 13

def mode
  @mode
end

#pathString (readonly)

Returns absolute guest path.

Returns:

  • (String)

    absolute guest path



7
8
9
# File 'lib/microsandbox/fs.rb', line 7

def path
  @path
end

#sizeInteger (readonly)

Returns size in bytes.

Returns:

  • (Integer)

    size in bytes



11
12
13
# File 'lib/microsandbox/fs.rb', line 11

def size
  @size
end

#typeSymbol (readonly)

Returns one of :file, :directory, :symlink, :other.

Returns:

  • (Symbol)

    one of :file, :directory, :symlink, :other



9
10
11
# File 'lib/microsandbox/fs.rb', line 9

def type
  @type
end

Instance Method Details

#directory?Boolean

Returns:

  • (Boolean)


34
# File 'lib/microsandbox/fs.rb', line 34

def directory?  = @type == :directory

#file?Boolean

Returns:

  • (Boolean)


33
# File 'lib/microsandbox/fs.rb', line 33

def file?       = @type == :file

#inspectObject



37
38
39
# File 'lib/microsandbox/fs.rb', line 37

def inspect
  "#<Microsandbox::FsEntry path=#{@path.inspect} type=#{@type} size=#{@size}>"
end

#modifiedTime?

Returns last-modified time, if known.

Returns:

  • (Time, nil)

    last-modified time, if known



29
30
31
# File 'lib/microsandbox/fs.rb', line 29

def modified
  @modified_ms && Time.at(@modified_ms / 1000.0)
end

#nameString

Returns the final path component.

Returns:

  • (String)

    the final path component



24
25
26
# File 'lib/microsandbox/fs.rb', line 24

def name
  File.basename(@path)
end

#symlink?Boolean

Returns:

  • (Boolean)


35
# File 'lib/microsandbox/fs.rb', line 35

def symlink?    = @type == :symlink