turbot-runner 0.1.43 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjQ3YzdmNDgwN2M1NmZlOWZjZjI0M2FkYjMyZDMxOTFhNWZhMTY1Mw==
4
+ ZjhmY2MyYTAzMTZiYmExNGY3NGVjZDJiMWU1OGYzZWM2ZjZlYmE4Ng==
5
5
  data.tar.gz: !binary |-
6
- MTFjY2E2M2EzZjZlOTZjZGUxMTU4Mjg4MjdhNTdkZTlmZTNiNzExOA==
6
+ YmEzZDBhOGY3NmM4MDQ3MWU4NWUyYWVkMzU2MTZjZjJjYzE5OGVkMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmI0ODkxZDhjMWZiZmFkYzViYTg3OTQ4ZjkyNWY3YTdkN2M0ODcwYzRkNTNh
10
- MzgwMWJiM2Q3NTgxNzIxZTA3ZTJiYTMxNmU4ZjM1ZTFhN2ZmYjlmY2JlNTBi
11
- MTdmZmVjM2NiNTdjODk4YmUxMzY5YWJlOGNhMjJhNjg1YjU2Yjg=
9
+ YzFmNjc0NjViNzEwOTgyN2RjZTgxMTcxYjBkZjllY2UyN2RjYjhlNTUwYzZj
10
+ MzcyZDA5YjkzMTY2NDlmM2ZlNDg2MDg0ZGFkMTc3MDlmNTVmZGVjMmE4Y2Iy
11
+ NTBkZGNiYjg3OGRlMzliMzYxYWRmOWRlYjJiYjQwMmQ2ZjYwYjc=
12
12
  data.tar.gz: !binary |-
13
- ZmQ3OTU5ZjY4NmQ5NmJmZWFkZjUyZjAzYjcxMTY4NjEzZTU3YTIyZjg0MGQ2
14
- Y2MyYzk1N2JkNzc0NzBjMzhiMTllMjE4Y2ZjZTIxZTU5MjNlZDE1ZDVmMDNm
15
- ODNmYTdiNDM3MjE5MmMzNWMyYTZlMzJkZGJjNjBmOTZkOGVjYjM=
13
+ M2VhZjdmYTI2Y2U5YTVmZGFiMTdhZjExYWI4YjMxZmU4OTlkYzRlMGMxZjBh
14
+ NTNmMjQwNjU2ZGNkZTI4ZWUyNmI4NzA5YWFjNjY2MWQ0ZWQzM2M3ZjcyM2Rl
15
+ NmE1NDNmMDNjYzZlNGI2YjFlZTJjYjk3ZGE4YTk2OWZjZDNiOWM=
@@ -9,30 +9,40 @@ module TurbotRunner
9
9
  schema_path = TurbotRunner.schema_path(data_type)
10
10
  error = Openc::JsonSchema.validate(schema_path, record)
11
11
 
12
- message = error.nil? ? nil : error[:message]
12
+ if error
13
+ return error[:message]
14
+ end
13
15
 
14
- if message.nil?
15
- identifying_hash = identifying_hash(record, identifying_fields)
16
- identifying_attributes = identifying_hash.reject {|k, v| v.nil? || v == ''}
17
- if identifying_attributes.empty?
18
- message = "There were no values provided for any of the identifying fields: #{identifying_fields.join(', ')}"
19
- end
16
+ identifying_hash = identifying_hash(record, identifying_fields)
17
+ if identifying_hash.nil?
18
+ return 'The value of an identifying field may not be a hash'
19
+ end
20
+
21
+ identifying_attributes = identifying_hash.reject {|k, v| v.nil? || v == ''}
22
+ if identifying_attributes.empty?
23
+ return "There were no values provided for any of the identifying fields: #{identifying_fields.join(', ')}"
20
24
  end
21
25
 
22
- if message.nil? && !seen_uids.nil?
26
+ if !seen_uids.nil?
23
27
  record_uid = record_uid(identifying_hash)
24
28
  if seen_uids.include?(record_uid)
25
- message = "Already seen record with these identifying fields: #{identifying_hash}"
29
+ return "Already seen record with these identifying fields: #{identifying_hash}"
26
30
  else
27
31
  seen_uids.add(record_uid)
28
32
  end
29
33
  end
30
34
 
31
- message
35
+ return nil
32
36
  end
33
37
 
34
38
  def identifying_hash(record, identifying_fields)
35
- TurbotRunner::Utils.flatten(record).slice(*identifying_fields)
39
+ flattened = TurbotRunner::Utils.flatten(record)
40
+ flattened.each do |k, v|
41
+ identifying_fields.each do |field|
42
+ return nil if k.start_with?("#{field}.")
43
+ end
44
+ end
45
+ flattened.slice(*identifying_fields)
36
46
  end
37
47
 
38
48
  def record_uid(identifying_hash)
@@ -1,3 +1,3 @@
1
1
  module TurbotRunner
2
- VERSION = '0.1.43'
2
+ VERSION = '0.1.44'
3
3
  end
@@ -94,11 +94,34 @@ describe TurbotRunner::Validator do
94
94
  }
95
95
 
96
96
  seen_uids = Set.new
97
- error = TurbotRunner::Validator.validate('primary-data', record, 'number', seen_uids)
97
+ error = TurbotRunner::Validator.validate('primary-data', record, ['number'], seen_uids)
98
98
  expect(error).to eq(nil)
99
99
 
100
- error = TurbotRunner::Validator.validate('primary-data', record, 'number', seen_uids)
100
+ error = TurbotRunner::Validator.validate('primary-data', record, ['number'], seen_uids)
101
101
  expect(error).to eq('Already seen record with these identifying fields: {"number"=>123}')
102
102
  end
103
103
  end
104
+
105
+ describe '.identifying_hash' do
106
+ specify 'returns expected hash' do
107
+ record = {'aaa' => 'bbb', 'yyy' => 'zzz'}
108
+ expect(TurbotRunner::Validator.identifying_hash(record, ['aaa'])).to eq({'aaa' => 'bbb'})
109
+
110
+ record = {'aaa' => {'bbb' => 'ccc'}, 'yyy' => 'zzz'}
111
+ expect(TurbotRunner::Validator.identifying_hash(record, ['aaa.bbb'])).to eq({'aaa.bbb' => 'ccc'})
112
+ end
113
+
114
+ specify 'returns empty hash for records with no values for identifying fields' do
115
+ record = {'yyy' => 'zzz'}
116
+ expect(TurbotRunner::Validator.identifying_hash(record, ['aaa'])).to eq({})
117
+ end
118
+
119
+ specify 'returns nil for records where value of identifying field is a hash' do
120
+ record = {'aaa' => {'bbb' => 'ccc'}, 'yyy' => 'zzz'}
121
+ expect(TurbotRunner::Validator.identifying_hash(record, ['aaa'])).to be(nil)
122
+
123
+ record = {'aaa' => {'bbb' => {'ccc' => 'ddd'}}, 'yyy' => 'zzz'}
124
+ expect(TurbotRunner::Validator.identifying_hash(record, ['aaa.bbb'])).to be(nil)
125
+ end
126
+ end
104
127
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.43
4
+ version: 0.1.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenCorporates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport