Class: Zonesync::Validator
- Inherits:
-
Struct
- Object
- Struct
- Zonesync::Validator
- Defined in:
- lib/zonesync/validator.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#operations ⇒ Object
Returns the value of attribute operations.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination
6 7 8 |
# File 'lib/zonesync/validator.rb', line 6 def destination @destination end |
#operations ⇒ Object
Returns the value of attribute operations
6 7 8 |
# File 'lib/zonesync/validator.rb', line 6 def operations @operations end |
#source ⇒ Object
Returns the value of attribute source
6 7 8 |
# File 'lib/zonesync/validator.rb', line 6 def source @source end |
Class Method Details
.call(operations, destination, source = nil, force: false) ⇒ Object
7 8 9 |
# File 'lib/zonesync/validator.rb', line 7 def self.call(operations, destination, source = nil, force: false) new(operations, destination, source).call(force: force) end |
Instance Method Details
#call(force: false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zonesync/validator.rb', line 11 def call(force: false) validation_error = ValidationError.new if !force && operations.any? && !manifest.existing? validation_error.add(MissingManifestError.new(manifest.generate)) end if !force && manifest.v1_format? && manifest.existing_checksum && manifest.existing_checksum != manifest.generate_checksum validation_error.add(ChecksumMismatchError.new(manifest.existing_checksum, manifest.generate_checksum)) end if !force && manifest.v2_format? integrity_error = validate_v2_manifest_integrity validation_error.add(integrity_error) if integrity_error end conflicts = operations.map do |method, args| method == :add ? validate_addition(args.first, force: force) : nil end.compact validation_error.add(ConflictError.new(conflicts)) if conflicts.any? if validation_error.errors.length == 1 raise validation_error.errors.first elsif validation_error.errors.length > 1 raise validation_error end nil end |