Class: Lich::Common::SetupFiles::FileInfo

Inherits:
Object
  • Object
show all
Defined in:
documented/common/setup_files.rb

Overview

Holds parsed YAML file content with metadata for cache validation.

Provides deep-cloned data access to prevent external mutation of cached settings, with automatic retry on transient Ruby iteration errors.

Constant Summary collapse

DEEP_COPY_ATTEMPTS =

Attempts at a deep clone before a transient iteration error propagates.

3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, name:, data:, mtime:, digest: nil) ⇒ void

Creates a FileInfo instance with parsed YAML content and metadata.

Parameters:

  • path (String) —

    directory path where the file was loaded from

  • name (String) —

    filename (basename without directory)

  • data (Hash) —

    parsed YAML content

  • mtime (Time) —

    file modification time from disk

  • digest (String, nil) (defaults to: nil) —

    SHA256 hexdigest for freshness validation; computed if not provided



64
65
66
67
68
69
70
# File 'documented/common/setup_files.rb', line 64

def initialize(path:, name:, data:, mtime:, digest: nil)
  @path = path
  @name = name
  @data = data
  @mtime = mtime
  @digest = digest
end

Instance Attribute Details

#digest ⇒ Object (readonly)

Returns the value of attribute digest.



54
55
56
# File 'documented/common/setup_files.rb', line 54

def digest
  @digest
end

#mtime ⇒ Object (readonly)

Returns the value of attribute mtime.



54
55
56
# File 'documented/common/setup_files.rb', line 54

def mtime
  @mtime
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



54
55
56
# File 'documented/common/setup_files.rb', line 54

def name
  @name
end

#path ⇒ Object (readonly)

Returns the value of attribute path.



54
55
56
# File 'documented/common/setup_files.rb', line 54

def path
  @path
end

Instance Method Details

#data ⇒ Object

Deep clone of data to prevent scripts from mutating cached settings.



73
74
75
# File 'documented/common/setup_files.rb', line 73

def data
  deep_copy(@data)
end

#inspect ⇒ String

Returns a string representation of this FileInfo for debugging.

Returns:

  • (String) —

    formatted as #<SetupFiles::FileInfo @name=..., @path=..., @mtime=..., @digest=...>



92
93
94
# File 'documented/common/setup_files.rb', line 92

def inspect
  "#<SetupFiles::FileInfo @name=#{@name}, @path=#{@path}, @mtime=#{@mtime}, @digest=#{@digest}>"
end

#peek(property) ⇒ Object

Efficient deep clone of a single property.



78
79
80
# File 'documented/common/setup_files.rb', line 78

def peek(property)
  deep_copy(@data[property.to_sym])
end

#to_s ⇒ String

Returns the full path to the cached file.

Returns:

  • (String) —

    path joined from directory and filename



85
86
87
# File 'documented/common/setup_files.rb', line 85

def to_s
  File.join(@path, @name)
end