Class: Textus::Port::Sentinel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Sentinel.



8
9
10
11
12
13
# File 'lib/textus/port/sentinel.rb', line 8

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.



6
7
8
# File 'lib/textus/port/sentinel.rb', line 6

def mode
  @mode
end

#sha256Object (readonly)

Returns the value of attribute sha256.



6
7
8
# File 'lib/textus/port/sentinel.rb', line 6

def sha256
  @sha256
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/textus/port/sentinel.rb', line 6

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/textus/port/sentinel.rb', line 6

def target
  @target
end

Instance Method Details

#drift?(file_stat) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/textus/port/sentinel.rb', line 17

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)


15
# File 'lib/textus/port/sentinel.rb', line 15

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