Class: Pvectl::Models::HostsFile

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/models/hosts_file.rb

Overview

Represents the contents of /etc/hosts on a Proxmox node.

Immutable value object. Created by Repositories::Hosts from API data. /etc/hosts is a per-node raw text file — pvectl does not parse or validate its contents.

Examples:

Creating from API response

hosts = HostsFile.new(node: "pve1",
                      data: "127.0.0.1 localhost\n",
                      digest: "abc123")

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ HostsFile

Creates a new HostsFile.

Parameters:

  • attributes (Hash) (defaults to: {})

    attribute key-value pairs (node, data, digest)



32
33
34
35
36
37
# File 'lib/pvectl/models/hosts_file.rb', line 32

def initialize(attributes = {})
  super
  @node = attributes[:node] || attributes["node"]
  @data = attributes[:data] || attributes["data"] || ""
  @digest = attributes[:digest] || attributes["digest"]
end

Instance Attribute Details

#dataString (readonly)

Returns raw /etc/hosts content (may be empty).

Returns:

  • (String)

    raw /etc/hosts content (may be empty)



24
25
26
# File 'lib/pvectl/models/hosts_file.rb', line 24

def data
  @data
end

#digestString? (readonly)

Returns digest used for optimistic locking on update.

Returns:

  • (String, nil)

    digest used for optimistic locking on update



27
28
29
# File 'lib/pvectl/models/hosts_file.rb', line 27

def digest
  @digest
end

#nodeString? (readonly)

Returns node name (not part of API payload — added by repository).

Returns:

  • (String, nil)

    node name (not part of API payload — added by repository)



21
22
23
# File 'lib/pvectl/models/hosts_file.rb', line 21

def node
  @node
end

Instance Method Details

#line_countInteger

Number of lines in the file (for compact list display).

Returns:

  • (Integer)

    line count



42
43
44
# File 'lib/pvectl/models/hosts_file.rb', line 42

def line_count
  data.lines.count
end