Module: TurbotRunner::Validator
Class Method Summary collapse
- .identifying_hash(record, identifying_fields) ⇒ Object
- .record_uid(identifying_hash) ⇒ Object
- .validate(data_type, record, identifying_fields, seen_uids) ⇒ Object
Instance Method Summary collapse
- #identifying_hash(record, identifying_fields) ⇒ Object
- #record_uid(identifying_hash) ⇒ Object
- #validate(data_type, record, identifying_fields, seen_uids) ⇒ Object
Class Method Details
.identifying_hash(record, identifying_fields) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/turbot_runner/validator.rb', line 38 def (record, ) flattened = TurbotRunner::Utils.flatten(record) flattened.each do |k, v| .each do |field| return nil if k.start_with?("#{field}.") end end flattened.slice(*) end |
.record_uid(identifying_hash) ⇒ Object
48 49 50 |
# File 'lib/turbot_runner/validator.rb', line 48 def record_uid() Digest::SHA1.hexdigest(.to_query) end |
.validate(data_type, record, identifying_fields, seen_uids) ⇒ Object
8 9 10 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 |
# File 'lib/turbot_runner/validator.rb', line 8 def validate(data_type, record, , seen_uids) schema_path = TurbotRunner.schema_path(data_type) error = Openc::JsonSchema.validate(schema_path, record) if error return error[:message] end = (record, ) if .nil? return 'The value of an identifying field may not be a hash' end = .reject {|k, v| v.nil? || v == ''} if .empty? return "There were no values provided for any of the identifying fields: #{.join(', ')}" end if !seen_uids.nil? record_uid = record_uid() if seen_uids.include?(record_uid) return "Already seen record with these identifying fields: #{}" else seen_uids.add(record_uid) end end nil end |
Instance Method Details
#identifying_hash(record, identifying_fields) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/turbot_runner/validator.rb', line 38 def (record, ) flattened = TurbotRunner::Utils.flatten(record) flattened.each do |k, v| .each do |field| return nil if k.start_with?("#{field}.") end end flattened.slice(*) end |
#record_uid(identifying_hash) ⇒ Object
48 49 50 |
# File 'lib/turbot_runner/validator.rb', line 48 def record_uid() Digest::SHA1.hexdigest(.to_query) end |
#validate(data_type, record, identifying_fields, seen_uids) ⇒ Object
8 9 10 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 |
# File 'lib/turbot_runner/validator.rb', line 8 def validate(data_type, record, , seen_uids) schema_path = TurbotRunner.schema_path(data_type) error = Openc::JsonSchema.validate(schema_path, record) if error return error[:message] end = (record, ) if .nil? return 'The value of an identifying field may not be a hash' end = .reject {|k, v| v.nil? || v == ''} if .empty? return "There were no values provided for any of the identifying fields: #{.join(', ')}" end if !seen_uids.nil? record_uid = record_uid() if seen_uids.include?(record_uid) return "Already seen record with these identifying fields: #{}" else seen_uids.add(record_uid) end end nil end |