Class: Synqa::HashCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/synqa.rb

Overview

A command to be executed on the remote system which calculates a hash value for a file (of a given length), in the format: hexadecimal-hash a-fixed-number-of-characters file-name

Direct Known Subclasses

Sha256Command, Sha256SumCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, length, spacerLen) ⇒ HashCommand

Returns a new instance of HashCommand.



58
59
60
61
62
# File 'lib/synqa.rb', line 58

def initialize(command, length, spacerLen)
  @command = command
  @length = length
  @spacerLen = spacerLen
end

Instance Attribute Details

#commandObject (readonly)

The command - a string or array of strings e.g. “sha256sum” or [“sha256”, “-r”]



50
51
52
# File 'lib/synqa.rb', line 50

def command
  @command
end

#lengthObject (readonly)

The length of the calculated hash value e.g. 64 for sha256



53
54
55
# File 'lib/synqa.rb', line 53

def length
  @length
end

#spacerLenObject (readonly)

The number of characters between the hash value and the file name (usually 1 or 2)



56
57
58
# File 'lib/synqa.rb', line 56

def spacerLen
  @spacerLen
end

Instance Method Details

#parseFileHashLine(baseDir, fileHashLine) ⇒ Object

Parse a hash line relative to a base directory, returning a RelativePathWithHash



65
66
67
68
69
70
71
72
73
# File 'lib/synqa.rb', line 65

def parseFileHashLine(baseDir, fileHashLine)
  hash = fileHashLine[0...length]
  fullPath = fileHashLine[(length + spacerLen)..-1]
  if fullPath.start_with?(baseDir)
    return RelativePathWithHash.new(fullPath[baseDir.length..-1], hash)
  else
    raise "File #{fullPath} from hash line is not in base dir #{baseDir}"
  end
end

#to_sObject



75
76
77
# File 'lib/synqa.rb', line 75

def to_s
  return command.join(" ")
end