Class: Zonesync::Validator

Inherits:
Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/zonesync/validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#destinationObject

Returns the value of attribute destination

Returns:

  • (Object)

    the current value of destination



6
7
8
# File 'lib/zonesync/validator.rb', line 6

def destination
  @destination
end

#operationsObject

Returns the value of attribute operations

Returns:

  • (Object)

    the current value of operations



6
7
8
# File 'lib/zonesync/validator.rb', line 6

def operations
  @operations
end

Class Method Details

.call(operations, destination, force: false) ⇒ Object



10
11
12
# File 'lib/zonesync/validator.rb', line 10

def self.call(operations, destination, force: false)
  new(operations, destination).call(force: force)
end

Instance Method Details

#call(force: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zonesync/validator.rb', line 15

def call(force: false)
  if !force && operations.any? && !manifest.existing?
    raise MissingManifestError.new(manifest.generate)
  end
  # Only validate checksums for v1 manifests (v2 manifests provide integrity via hashes)
  if !force && manifest.v1_format? && manifest.existing_checksum && manifest.existing_checksum != manifest.generate_checksum
    raise ChecksumMismatchError.new(manifest.existing_checksum, manifest.generate_checksum)
  end
  operations.each do |method, args|
    if method == :add
      validate_addition args.first, force: force
    end
  end
  nil
end