Class: DS::Manifest::BaseIdValidator
- Inherits:
-
Object
- Object
- DS::Manifest::BaseIdValidator
- Defined in:
- lib/ds/manifest/base_id_validator.rb
Overview
A BaseIdValidator is a base class for a
cacheable ID validator for sources. The validator is responsible
for opening and caching source files and dtermining that one
record is found for each source id at the specified
id_location in the parsed source.
The motivation for this class is to handle ID validation for source types that can have multiple records per source file, saving the time required to parse the source file for each check.
Concrete subclasses of BaseIdValidator must implement
- +#locate_record+, required this class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #add_error(message) ⇒ Object
- #handle_count_error(count, inst_id, location_in_source) ⇒ Object
-
#initialize(source) ⇒ void
constructor
Create a new ID Validator.
-
#locate_record(source_path, id, id_location) ⇒ Array<Object>
Locates a record based on the given source path, ID, and ID location.
-
#valid?(file_path, id, id_location) ⇒ Boolean
Checks if the given file path, id, and id location are valid.
Constructor Details
#initialize(source) ⇒ void
Create a new ID Validator
30 31 32 33 |
# File 'lib/ds/manifest/base_id_validator.rb', line 30 def initialize source @source = source @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
22 23 24 |
# File 'lib/ds/manifest/base_id_validator.rb', line 22 def errors @errors end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
23 24 25 |
# File 'lib/ds/manifest/base_id_validator.rb', line 23 def source @source end |
Instance Method Details
#add_error(message) ⇒ Object
71 72 73 |
# File 'lib/ds/manifest/base_id_validator.rb', line 71 def add_error @errors << end |
#handle_count_error(count, inst_id, location_in_source) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ds/manifest/base_id_validator.rb', line 60 def handle_count_error count, inst_id, location_in_source return if count == 1 if count > 1 add_error "ERROR: Multiple records (#{count}) found for id: #{inst_id} (location: #{location_in_source})" elsif count == 0 add_error "ERROR: No records found for id: #{inst_id} (location: #{location_in_source})" end nil end |
#locate_record(source_path, id, id_location) ⇒ Array<Object>
Locates a record based on the given source path, ID, and ID location.
56 57 58 |
# File 'lib/ds/manifest/base_id_validator.rb', line 56 def locate_record source_path, id, id_location raise NotImplementedError end |
#valid?(file_path, id, id_location) ⇒ Boolean
Checks if the given file path, id, and id location are valid.
41 42 43 44 45 46 47 |
# File 'lib/ds/manifest/base_id_validator.rb', line 41 def valid? file_path, id, id_location records = locate_record file_path, id, id_location return true if records.size == 1 handle_count_error records.size, id, id_location false end |