Class: Synqa::HashCommand
- Inherits:
-
Object
- Object
- Synqa::HashCommand
- 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
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
The command - a string or array of strings e.g.
-
#length ⇒ Object
readonly
The length of the calculated hash value e.g.
-
#spacerLen ⇒ Object
readonly
The number of characters between the hash value and the file name (usually 1 or 2).
Instance Method Summary collapse
-
#initialize(command, length, spacerLen) ⇒ HashCommand
constructor
A new instance of HashCommand.
-
#parseFileHashLine(baseDir, fileHashLine) ⇒ Object
Parse a hash line relative to a base directory, returning a RelativePathWithHash.
- #to_s ⇒ Object
Constructor Details
#initialize(command, length, spacerLen) ⇒ HashCommand
Returns a new instance of HashCommand.
67 68 69 70 71 |
# File 'lib/synqa.rb', line 67 def initialize(command, length, spacerLen) @command = command @length = length @spacerLen = spacerLen end |
Instance Attribute Details
#command ⇒ Object (readonly)
The command - a string or array of strings e.g. “sha256sum” or [“sha256”, “-r”]
59 60 61 |
# File 'lib/synqa.rb', line 59 def command @command end |
#length ⇒ Object (readonly)
The length of the calculated hash value e.g. 64 for sha256
62 63 64 |
# File 'lib/synqa.rb', line 62 def length @length end |
#spacerLen ⇒ Object (readonly)
The number of characters between the hash value and the file name (usually 1 or 2)
65 66 67 |
# File 'lib/synqa.rb', line 65 def spacerLen @spacerLen end |
Instance Method Details
#parseFileHashLine(baseDir, fileHashLine) ⇒ Object
Parse a hash line relative to a base directory, returning a RelativePathWithHash
74 75 76 77 78 79 80 81 82 |
# File 'lib/synqa.rb', line 74 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_s ⇒ Object
84 85 86 |
# File 'lib/synqa.rb', line 84 def to_s return command.join(" ") end |