Class: E2B::Models::EntryInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/e2b/models/entry_info.rb

Overview

Information about a filesystem entry (file or directory) in the sandbox

Represents the protobuf EntryInfo message returned by filesystem RPCs such as Stat, ListDir, and others. Contains metadata including name, type, path, size, permissions, ownership, and modification time.

Examples:

entry = sandbox.files.stat("/home/user/hello.txt")
puts entry.name          # => "hello.txt"
puts entry.size          # => 13
puts entry.file?         # => true
puts entry.directory?    # => false
puts entry.permissions   # => "0644"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, path:, size: 0, mode: 0, permissions: "", owner: "", group: "", modified_time: nil, symlink_target: nil) ⇒ EntryInfo

Returns a new instance of EntryInfo.

Parameters:

  • name (String)

    Name of the file or directory

  • type (String)

    Type of entry (one of FileType constants)

  • path (String)

    Full path in the sandbox filesystem

  • size (Integer) (defaults to: 0)

    Size in bytes

  • mode (Integer) (defaults to: 0)

    Unix file mode

  • permissions (String) (defaults to: "")

    Permissions string

  • owner (String) (defaults to: "")

    Owner username

  • group (String) (defaults to: "")

    Group name

  • modified_time (Time, nil) (defaults to: nil)

    Last modification time

  • symlink_target (String, nil) (defaults to: nil)

    Symlink target path



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/e2b/models/entry_info.rb', line 143

def initialize(name:, type:, path:, size: 0, mode: 0, permissions: "",
               owner: "", group: "", modified_time: nil, symlink_target: nil)
  @name = name
  @type = type
  @path = path
  @size = size
  @mode = mode
  @permissions = permissions
  @owner = owner
  @group = group
  @modified_time = modified_time
  @symlink_target = symlink_target
end

Instance Attribute Details

#groupString (readonly)

Returns Group name.

Returns:

  • (String)

    Group name



125
126
127
# File 'lib/e2b/models/entry_info.rb', line 125

def group
  @group
end

#modeInteger (readonly)

Returns Unix file mode (e.g., 0o644).

Returns:

  • (Integer)

    Unix file mode (e.g., 0o644)



116
117
118
# File 'lib/e2b/models/entry_info.rb', line 116

def mode
  @mode
end

#modified_timeTime? (readonly)

Returns Last modification time.

Returns:

  • (Time, nil)

    Last modification time



128
129
130
# File 'lib/e2b/models/entry_info.rb', line 128

def modified_time
  @modified_time
end

#nameString (readonly)

Returns Name of the file or directory.

Returns:

  • (String)

    Name of the file or directory



104
105
106
# File 'lib/e2b/models/entry_info.rb', line 104

def name
  @name
end

#ownerString (readonly)

Returns Owner username.

Returns:

  • (String)

    Owner username



122
123
124
# File 'lib/e2b/models/entry_info.rb', line 122

def owner
  @owner
end

#pathString (readonly)

Returns Full path to the entry in the sandbox filesystem.

Returns:

  • (String)

    Full path to the entry in the sandbox filesystem



110
111
112
# File 'lib/e2b/models/entry_info.rb', line 110

def path
  @path
end

#permissionsString (readonly)

Returns Permissions string (e.g., “0644”).

Returns:

  • (String)

    Permissions string (e.g., “0644”)



119
120
121
# File 'lib/e2b/models/entry_info.rb', line 119

def permissions
  @permissions
end

#sizeInteger (readonly)

Returns Size in bytes.

Returns:

  • (Integer)

    Size in bytes



113
114
115
# File 'lib/e2b/models/entry_info.rb', line 113

def size
  @size
end

Returns Symlink target path, if the entry is a symlink.

Returns:

  • (String, nil)

    Symlink target path, if the entry is a symlink



131
132
133
# File 'lib/e2b/models/entry_info.rb', line 131

def symlink_target
  @symlink_target
end

#typeString (readonly)

Returns Type of entry (one of FileType constants).

Returns:

  • (String)

    Type of entry (one of FileType constants)



107
108
109
# File 'lib/e2b/models/entry_info.rb', line 107

def type
  @type
end

Class Method Details

.from_hash(data) ⇒ EntryInfo?

Create from RPC response hash

Handles both numeric protobuf enum values and string enum names, as well as camelCase and snake_case key formats.

Parameters:

  • data (Hash)

    Raw entry data from the RPC response

Returns:

  • (EntryInfo, nil)

    The parsed entry, or nil if data is not a Hash



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/e2b/models/entry_info.rb', line 178

def self.from_hash(data)
  return nil unless data.is_a?(Hash)

  type_value = data["type"] || data[:type]
  type_name = case type_value
              when 1, "FILE_TYPE_FILE" then FileType::FILE
              when 2, "FILE_TYPE_DIRECTORY" then FileType::DIRECTORY
              else type_value.to_s
              end

  modified = data["modifiedTime"] || data["modified_time"] || data[:modifiedTime] || data[:modified_time]
  modified_time = parse_modified_time(modified)

  new(
    name: data["name"] || data[:name] || "",
    type: type_name,
    path: data["path"] || data[:path] || "",
    size: (data["size"] || data[:size] || 0).to_i,
    mode: (data["mode"] || data[:mode] || 0).to_i,
    permissions: data["permissions"] || data[:permissions] || "",
    owner: data["owner"] || data[:owner] || "",
    group: data["group"] || data[:group] || "",
    modified_time: modified_time,
    symlink_target: data["symlinkTarget"] || data["symlink_target"] || data[:symlinkTarget] || data[:symlink_target]
  )
end

Instance Method Details

#directory?Boolean

Check if this entry is a directory

Returns:

  • (Boolean)


167
168
169
# File 'lib/e2b/models/entry_info.rb', line 167

def directory?
  @type == FileType::DIRECTORY
end

#file?Boolean

Check if this entry is a regular file

Returns:

  • (Boolean)


160
161
162
# File 'lib/e2b/models/entry_info.rb', line 160

def file?
  @type == FileType::FILE
end