remi 0.2.36 → 0.2.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/features/json.feature +31 -0
- data/features/step_definitions/remi_step.rb +7 -5
- data/jobs/json_job.rb +30 -0
- data/lib/remi/cucumber/business_rules.rb +14 -8
- data/lib/remi/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4053acf8d3794062479455dd42afc7d3820832b5
|
4
|
+
data.tar.gz: 363985988b27cda161515842f3469d8b34487904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5882b3ea3e2ee615e7c280108138a5e3cb8f7d30321655191c2973a083e722f974a4250ed40f1aa5f52ee610529b0078051355c160b914feb821e7f652117dff
|
7
|
+
data.tar.gz: 6cfff4363a00d7b030a700340da60e1b590432f67ff74e6adc96783b6e14be3078c244f890f8f4a77fddfabc1567d18cb64657375b0a882f51cc8c59a25b574c
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
Feature: This tests using json data in tests.
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given the job is 'Json'
|
5
|
+
And the job source 'Source Data'
|
6
|
+
And the job target 'Target Data'
|
7
|
+
And the source 'Source Data'
|
8
|
+
And the target 'Target Data'
|
9
|
+
|
10
|
+
|
11
|
+
Scenario: Using JSON data in an example record.
|
12
|
+
|
13
|
+
Given the following example record for 'Source Data':
|
14
|
+
| json_array | json_hash |
|
15
|
+
| [ "one", "two" ] | { "name": "Darwin" } |
|
16
|
+
|
17
|
+
Then the target field 'second_element' is populated with "two"
|
18
|
+
And the target field 'name_field' is populated with "Darwin"
|
19
|
+
|
20
|
+
|
21
|
+
Scenario: Using JSON data in long form
|
22
|
+
|
23
|
+
Given the source field 'json_hash' has the multiline value
|
24
|
+
"""
|
25
|
+
{
|
26
|
+
"id": 97,
|
27
|
+
"name": "Darwin",
|
28
|
+
"birthday": "1809-02-12"
|
29
|
+
}
|
30
|
+
"""
|
31
|
+
And the target field 'name_field' is populated with "Darwin"
|
@@ -139,16 +139,16 @@ Given /^the source field (?:has|is set to) the value "([^"]*)"$/ do |value|
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
Given /^the source field '([^']+)' (?:has|is set to) the
|
142
|
+
Given /^the source field '([^']+)' (?:has|is set to) the multiline value$/ do |source_field, value|
|
143
143
|
step "the source field '#{source_field}'"
|
144
144
|
|
145
145
|
source_name, source_field_name = @brt.sources.parse_full_field(source_field)
|
146
|
-
@brt.sources[source_name].fields[source_field_name].value =
|
146
|
+
@brt.sources[source_name].fields[source_field_name].value = Remi::BusinessRules::ParseFormula.parse(value)
|
147
147
|
end
|
148
148
|
|
149
|
-
Given /^the source field (?:has|is set to) the
|
149
|
+
Given /^the source field (?:has|is set to) the multiline value$/ do |value|
|
150
150
|
@brt.sources.fields.each do |field|
|
151
|
-
step "the source field '#{field.full_name}'
|
151
|
+
step "the source field '#{field.full_name}' has the multiline value #{value}"
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -254,6 +254,8 @@ Then /^the target field is copied from the source field$/ do
|
|
254
254
|
end
|
255
255
|
|
256
256
|
Then /^the target field '([^']+)' is (?:set to the value|populated with) "([^"]*)"$/ do |target_field, value|
|
257
|
+
value = value.gsub(/(\\n|\\t)/, '\n' => "\n", '\t' => "\t" )
|
258
|
+
|
257
259
|
expect_cucumber {
|
258
260
|
target_names, target_field_name = @brt.targets.parse_full_field(target_field, multi: true)
|
259
261
|
|
@@ -336,7 +338,7 @@ end
|
|
336
338
|
### Transforms
|
337
339
|
|
338
340
|
Then /^the target field '([^']+)' is a concatenation of the source fields '(.+)', delimited by "([^"]*)"$/ do |target_field, source_field_list, delimiter|
|
339
|
-
delimiter = delimiter.gsub(/(\\n|\\t)/, '\n' => "\n", '\t' => "t" )
|
341
|
+
delimiter = delimiter.gsub(/(\\n|\\t)/, '\n' => "\n", '\t' => "\t" )
|
340
342
|
source_fields = "'#{source_field_list}'".gsub(' and ', ', ').split(',').map do |field_with_quotes|
|
341
343
|
full_field_name = field_with_quotes.match(/'(.+)'/)[1]
|
342
344
|
|
data/jobs/json_job.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'all_jobs_shared'
|
2
|
+
|
3
|
+
class JsonJob
|
4
|
+
include AllJobsShared
|
5
|
+
|
6
|
+
define_source :source_data, Remi::DataSource::DataFrame,
|
7
|
+
fields: {
|
8
|
+
:json_array => { type: :json },
|
9
|
+
:json_hash => { type: :json }
|
10
|
+
}
|
11
|
+
|
12
|
+
define_target :target_data, Remi::DataTarget::DataFrame,
|
13
|
+
fields: {
|
14
|
+
:second_element => {},
|
15
|
+
:name_field => {}
|
16
|
+
}
|
17
|
+
|
18
|
+
define_transform :main do
|
19
|
+
Remi::SourceToTargetMap.apply(source_data.df, target_data.df, source_metadata: source_data.fields) do
|
20
|
+
map source(:json_array) .target(:second_element)
|
21
|
+
.transform(->(*values) { values[1] })
|
22
|
+
# This is NOT the way I would like it to work, but we need to do some work on STTM first
|
23
|
+
map source(:json_hash) .target(:name_field)
|
24
|
+
.transform(->(*json_hash) { json_hash.to_h['name'] })
|
25
|
+
# preferred
|
26
|
+
# map source(:json_hash) .target(:name_field)
|
27
|
+
# .transform(->(json_hash) { json_hash['name'] })
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -293,12 +293,6 @@ module Remi::BusinessRules
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
|
-
# For debugging only
|
297
|
-
def _df
|
298
|
-
@data_subject.df
|
299
|
-
end
|
300
|
-
|
301
|
-
|
302
296
|
# Would like to have this return a new DataSubject and not a dataframe.
|
303
297
|
# Need more robust duping to make that feasible.
|
304
298
|
# Don't use results for anything more than size.
|
@@ -333,7 +327,13 @@ module Remi::BusinessRules
|
|
333
327
|
end
|
334
328
|
|
335
329
|
def example_to_df(example)
|
336
|
-
example.to_df(@data_subject.df.row[0].to_h, field_symbolizer: @data_subject.field_symbolizer)
|
330
|
+
df = example.to_df(@data_subject.df.row[0].to_h, field_symbolizer: @data_subject.field_symbolizer)
|
331
|
+
data_subject.fields.each do |vector, metadata|
|
332
|
+
if metadata[:type] == :json
|
333
|
+
df[vector].recode! { |v| JSON.parse(v) rescue v }
|
334
|
+
end
|
335
|
+
end
|
336
|
+
df
|
337
337
|
end
|
338
338
|
|
339
339
|
def stub_data_with(example)
|
@@ -486,7 +486,13 @@ module Remi::BusinessRules
|
|
486
486
|
end
|
487
487
|
|
488
488
|
def value=(arg)
|
489
|
-
|
489
|
+
typed_arg = if metadata[:type] == :json
|
490
|
+
JSON.parse(arg)
|
491
|
+
else
|
492
|
+
arg
|
493
|
+
end
|
494
|
+
|
495
|
+
vector.recode! { |_v| typed_arg }
|
490
496
|
end
|
491
497
|
end
|
492
498
|
|
data/lib/remi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sterling Paramore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bond
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- features/csv_file_target_job.feature
|
187
187
|
- features/examples.feature
|
188
188
|
- features/formulas.feature
|
189
|
+
- features/json.feature
|
189
190
|
- features/metadata.feature
|
190
191
|
- features/parameters.feature
|
191
192
|
- features/sample_job.feature
|
@@ -205,6 +206,7 @@ files:
|
|
205
206
|
- jobs/all_jobs_shared.rb
|
206
207
|
- jobs/copy_source_job.rb
|
207
208
|
- jobs/csv_file_target_job.rb
|
209
|
+
- jobs/json_job.rb
|
208
210
|
- jobs/metadata_job.rb
|
209
211
|
- jobs/parameters_job.rb
|
210
212
|
- jobs/sample_job.rb
|
@@ -289,6 +291,7 @@ test_files:
|
|
289
291
|
- features/csv_file_target_job.feature
|
290
292
|
- features/examples.feature
|
291
293
|
- features/formulas.feature
|
294
|
+
- features/json.feature
|
292
295
|
- features/metadata.feature
|
293
296
|
- features/parameters.feature
|
294
297
|
- features/sample_job.feature
|