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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10fd270314dd717896ad16248ae4dbeafa652b1f
4
- data.tar.gz: a9573d012b827f91ab454a3a8cdf72e1815b0501
3
+ metadata.gz: bca0112699121f9c35cbccfed47361e7defc2478
4
+ data.tar.gz: 153874a0d4c2d826435bd8287937980f398d4b38
5
5
  SHA512:
6
- metadata.gz: a0f38ca8a6af51eaef4272130e866e070397e31f84d43b8f1190edb51da847f064eeefccf8c3bd8ac126067ca66e9f287884097479ac931ae2e63c8621ec7e2f
7
- data.tar.gz: a3e360dc2ef4613dba3bf6f38ac2bfc9c0c7f5a7494be5dc6910602a28ab53806335e31df7c8117737bd9ecfbfc623f3a1e079a19b087e66a3f6d4decfb077fd
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, [Symbol])
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
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Masamune
24
- VERSION = '0.18.9'.freeze
24
+ VERSION = '0.18.10'.freeze
25
25
  end
@@ -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.9
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-23 00:00:00.000000000 Z
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor