Class: Textus::Domain::Sentinel

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/domain/sentinel.rb

Overview

Pure value object representing a published-file sentinel. Holds the recorded target path, source path, sha256 checksum, and publish mode. Has no filesystem I/O — path layout and persistence live in Ports::SentinelStore; predicate methods accept a FileStat port for existence and content checks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target:, source:, sha256:, mode:) ⇒ Sentinel

Returns a new instance of Sentinel.



13
14
15
16
17
18
# File 'lib/textus/domain/sentinel.rb', line 13

def initialize(target:, source:, sha256:, mode:)
  @target = target
  @source = source
  @sha256 = sha256
  @mode = mode
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



11
12
13
# File 'lib/textus/domain/sentinel.rb', line 11

def mode
  @mode
end

#sha256Object (readonly)

Returns the value of attribute sha256.



11
12
13
# File 'lib/textus/domain/sentinel.rb', line 11

def sha256
  @sha256
end

#sourceObject (readonly)

Returns the value of attribute source.



11
12
13
# File 'lib/textus/domain/sentinel.rb', line 11

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



11
12
13
# File 'lib/textus/domain/sentinel.rb', line 11

def target
  @target
end

Instance Method Details

#drift?(file_stat) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/textus/domain/sentinel.rb', line 22

def drift?(file_stat)
  return false if orphan?(file_stat)
  return false if @sha256.nil?

  Digest::SHA256.hexdigest(file_stat.read(@target)) != @sha256
end

#orphan?(file_stat) ⇒ Boolean

Returns:

  • (Boolean)


20
# File 'lib/textus/domain/sentinel.rb', line 20

def orphan?(file_stat) = @target.nil? || !file_stat.exists?(@target)