masamune 0.18.9 → 0.18.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/masamune/schema/column.rb +5 -1
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/schema/map_spec.rb +145 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bca0112699121f9c35cbccfed47361e7defc2478
|
4
|
+
data.tar.gz: 153874a0d4c2d826435bd8287937980f398d4b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dadcc2005177b8e661b4eeb5c09ba26209e4685ecfa61c0fd008df4409743ac0e2488b7b03374be0d9b47b8bad98483ce8c14069a0e45fb95fb0d02e1020ffe7
|
7
|
+
data.tar.gz: 2ca09ebf967d47edc04d8e5d12455201faceafd10eca5ade719f003c88143822a0a5df06a8e2a00b6ecd82daba9a9744302cdc37f6e28c9556956c6be778fade
|
@@ -278,7 +278,7 @@ module Masamune::Schema
|
|
278
278
|
when Hash
|
279
279
|
value
|
280
280
|
when String
|
281
|
-
YAML.safe_load(value,
|
281
|
+
YAML.safe_load(value, allowed_yaml_sub_type)
|
282
282
|
when nil
|
283
283
|
{}
|
284
284
|
end
|
@@ -492,5 +492,9 @@ module Masamune::Schema
|
|
492
492
|
[ruby_value(value, false)].to_json
|
493
493
|
end
|
494
494
|
end
|
495
|
+
|
496
|
+
def allowed_yaml_sub_type
|
497
|
+
@allowed_yaml_sub_type ||= [Symbol] + Array.wrap(sub_type)
|
498
|
+
end
|
495
499
|
end
|
496
500
|
end
|
data/lib/masamune/version.rb
CHANGED
@@ -446,6 +446,151 @@ describe Masamune::Schema::Map do
|
|
446
446
|
it_behaves_like 'apply input/output'
|
447
447
|
end
|
448
448
|
|
449
|
+
context 'from csv file to tsv file with unknown yaml sub_type' do
|
450
|
+
before do
|
451
|
+
expect(environment.logger).to receive(:warn).with(/Could not coerce/).ordered
|
452
|
+
expect(environment.logger).to receive(:debug).with(
|
453
|
+
message: "Could not coerce '--- !map:ActiveSupport::HashWithIndifferentAccess\nenabled: true\n' into :yaml for column 'preferences'",
|
454
|
+
source: 'input_stage',
|
455
|
+
target: 'output_stage',
|
456
|
+
file: input.path,
|
457
|
+
line: 1,
|
458
|
+
row: {
|
459
|
+
'id' => '2',
|
460
|
+
'tenant_id' => '40',
|
461
|
+
'deleted_at' => '2014-02-26T18:15:51.000Z',
|
462
|
+
'admin' => 'FALSE',
|
463
|
+
'preferences' => "--- !map:ActiveSupport::HashWithIndifferentAccess\nenabled: true\n"
|
464
|
+
}
|
465
|
+
).ordered
|
466
|
+
end
|
467
|
+
|
468
|
+
before do
|
469
|
+
catalog.schema :files do
|
470
|
+
file 'input', format: :csv, headers: true, json_encoding: :quoted do
|
471
|
+
column 'id', type: :integer
|
472
|
+
column 'tenant_id', type: :integer
|
473
|
+
column 'admin', type: :boolean
|
474
|
+
column 'preferences', type: :yaml
|
475
|
+
column 'deleted_at', type: :timestamp, null: true
|
476
|
+
end
|
477
|
+
|
478
|
+
file 'output', format: :tsv, headers: false do
|
479
|
+
column 'id', type: :integer
|
480
|
+
column 'tenant_id', type: :integer
|
481
|
+
column 'admin', type: :boolean
|
482
|
+
column 'preferences', type: :json
|
483
|
+
column 'deleted_at', type: :timestamp, null: true
|
484
|
+
end
|
485
|
+
|
486
|
+
map from: files.input, to: files.output do |row|
|
487
|
+
{
|
488
|
+
'id' => row[:id],
|
489
|
+
'tenant_id' => row[:tenant_id],
|
490
|
+
'deleted_at' => row[:deleted_at],
|
491
|
+
'admin' => row[:admin],
|
492
|
+
'preferences' => row[:preferences]
|
493
|
+
}
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
let(:source) do
|
499
|
+
catalog.files.input
|
500
|
+
end
|
501
|
+
|
502
|
+
let(:target) do
|
503
|
+
catalog.files.output
|
504
|
+
end
|
505
|
+
|
506
|
+
let(:source_data) do
|
507
|
+
<<-EOS.strip_heredoc
|
508
|
+
id,tenant_id,deleted_at,admin,preferences
|
509
|
+
1,30,,FALSE,"--- {}
|
510
|
+
"
|
511
|
+
2,40,2014-02-26T18:15:51.000Z,FALSE,"--- !map:ActiveSupport::HashWithIndifferentAccess
|
512
|
+
enabled: true
|
513
|
+
"
|
514
|
+
EOS
|
515
|
+
end
|
516
|
+
|
517
|
+
let(:target_data) do
|
518
|
+
<<-EOS.strip_heredoc
|
519
|
+
1 30 FALSE {}
|
520
|
+
EOS
|
521
|
+
end
|
522
|
+
|
523
|
+
it 'should match target data' do
|
524
|
+
is_expected.to eq(target_data)
|
525
|
+
end
|
526
|
+
|
527
|
+
it_behaves_like 'apply input/output'
|
528
|
+
end
|
529
|
+
|
530
|
+
context 'from csv file to tsv file with yaml sub_type' do
|
531
|
+
before do
|
532
|
+
catalog.schema :files do
|
533
|
+
file 'input', format: :csv, headers: true, json_encoding: :quoted do
|
534
|
+
column 'id', type: :integer
|
535
|
+
column 'tenant_id', type: :integer
|
536
|
+
column 'admin', type: :boolean
|
537
|
+
column 'preferences', type: :yaml, sub_type: ActiveSupport::HashWithIndifferentAccess
|
538
|
+
column 'deleted_at', type: :timestamp, null: true
|
539
|
+
end
|
540
|
+
|
541
|
+
file 'output', format: :tsv, headers: false do
|
542
|
+
column 'id', type: :integer
|
543
|
+
column 'tenant_id', type: :integer
|
544
|
+
column 'admin', type: :boolean
|
545
|
+
column 'preferences', type: :json
|
546
|
+
column 'deleted_at', type: :timestamp, null: true
|
547
|
+
end
|
548
|
+
|
549
|
+
map from: files.input, to: files.output do |row|
|
550
|
+
{
|
551
|
+
'id' => row[:id],
|
552
|
+
'tenant_id' => row[:tenant_id],
|
553
|
+
'deleted_at' => row[:deleted_at],
|
554
|
+
'admin' => row[:admin],
|
555
|
+
'preferences' => row[:preferences]
|
556
|
+
}
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
let(:source) do
|
562
|
+
catalog.files.input
|
563
|
+
end
|
564
|
+
|
565
|
+
let(:target) do
|
566
|
+
catalog.files.output
|
567
|
+
end
|
568
|
+
|
569
|
+
let(:source_data) do
|
570
|
+
<<-EOS.strip_heredoc
|
571
|
+
id,tenant_id,deleted_at,admin,preferences
|
572
|
+
1,30,,FALSE,"--- {}
|
573
|
+
"
|
574
|
+
2,40,2014-02-26T18:15:51.000Z,FALSE,"--- !map:ActiveSupport::HashWithIndifferentAccess
|
575
|
+
enabled: true
|
576
|
+
"
|
577
|
+
EOS
|
578
|
+
end
|
579
|
+
|
580
|
+
let(:target_data) do
|
581
|
+
<<-EOS.strip_heredoc
|
582
|
+
1 30 FALSE {}
|
583
|
+
2 40 2014-02-26T18:15:51.000Z FALSE "{""enabled"":true}"
|
584
|
+
EOS
|
585
|
+
end
|
586
|
+
|
587
|
+
it 'should match target data' do
|
588
|
+
is_expected.to eq(target_data)
|
589
|
+
end
|
590
|
+
|
591
|
+
it_behaves_like 'apply input/output'
|
592
|
+
end
|
593
|
+
|
449
594
|
context 'with multiple outputs' do
|
450
595
|
before do
|
451
596
|
catalog.schema :files do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: masamune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Andrews
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|