data_migrater 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/lib/data_migrater/csv.rb +12 -4
- data/lib/data_migrater/version.rb +1 -1
- data/spec/csv/csv_delete_spec.rb +54 -10
- data/spec/csv/csv_spec.rb +22 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f399d2a9cb8f0b2b4308d800542e259b9944d208ff2ed31ecdf8c001dbbc3861
|
4
|
+
data.tar.gz: 75dda4543f8a3eefac6c7158763891f51dbd73585653a0dfaeee89022f691663
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec764ed1b0e4804054925a43443fc470f1e14d5698e0979cc3dccd264661e91ce8a77cfbe199c2d8ca9364d98c134445003a2c88121bfe0ff82cfcb77f3cc0f6
|
7
|
+
data.tar.gz: 644d8766d959b196401874fbaa7edfcfc32b3590dd0ebcf11a6a37c51b58ec891202c29c0a27837bb14a54c65d46fcfcea8e3c01565173a9dec8e239d815e48a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/data_migrater/csv.rb
CHANGED
@@ -8,7 +8,9 @@ module DataMigrater
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
def csv(processor: ::SmarterCSV)
|
11
|
-
s3.download if
|
11
|
+
s3.download if s3_provider?
|
12
|
+
|
13
|
+
return [] unless File.exist?(csv_path)
|
12
14
|
|
13
15
|
processor.process csv_path, csv_options
|
14
16
|
end
|
@@ -20,7 +22,9 @@ module DataMigrater
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def csv_delete
|
23
|
-
s3.delete
|
25
|
+
s3.delete if s3_provider?
|
26
|
+
|
27
|
+
File.delete(csv_path) if File.exist?(csv_path)
|
24
28
|
end
|
25
29
|
|
26
30
|
private
|
@@ -41,12 +45,16 @@ module DataMigrater
|
|
41
45
|
self.class.csv_options
|
42
46
|
end
|
43
47
|
|
48
|
+
def s3
|
49
|
+
@s3 ||= DataMigrater::S3.new(csv_bucket, s3_credentials, csv_path)
|
50
|
+
end
|
51
|
+
|
44
52
|
def s3_credentials
|
45
53
|
csv_options.delete(:credentials) || {}
|
46
54
|
end
|
47
55
|
|
48
|
-
def
|
49
|
-
@
|
56
|
+
def s3_provider?
|
57
|
+
@s3_provider ||= csv_options.delete(:provider) == :s3
|
50
58
|
end
|
51
59
|
end
|
52
60
|
|
data/spec/csv/csv_delete_spec.rb
CHANGED
@@ -3,21 +3,65 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe '#csv_delete' do
|
6
|
-
|
6
|
+
context 'when provider is s3' do
|
7
|
+
let!(:s3) { instance_double 'DataMigrater::S3' }
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
before do
|
10
|
+
stub_const 'Dummy', Class.new
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
Dummy.class_eval { include DataMigrater::CSV }
|
13
|
+
Dummy.class_eval { data_csv provider: :s3 }
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
allow(DataMigrater::S3).to receive(:new)
|
16
|
+
.with('data-migrater', {}, 'db/data_migrate/support/csv/dummy.csv').and_return s3
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'delegates delete to s3 object and deletes the existent file' do
|
20
|
+
allow(File).to receive(:exist?).and_return true
|
21
|
+
|
22
|
+
expect(s3).to receive(:delete)
|
23
|
+
|
24
|
+
expect(File).to receive(:delete).with 'db/data_migrate/support/csv/dummy.csv'
|
25
|
+
|
26
|
+
Dummy.new.csv_delete
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when has no provider' do
|
31
|
+
before do
|
32
|
+
stub_const 'Dummy', Class.new
|
33
|
+
|
34
|
+
Dummy.class_eval { include DataMigrater::CSV }
|
35
|
+
Dummy.class_eval { data_csv }
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not delegates delete to s3 object' do
|
39
|
+
expect(DataMigrater::S3).not_to receive(:new)
|
40
|
+
|
41
|
+
Dummy.new.csv_delete
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'deletes the existent file' do
|
45
|
+
allow(File).to receive(:exist?).and_return true
|
46
|
+
|
47
|
+
expect(File).to receive(:delete).with 'db/data_migrate/support/csv/dummy.csv'
|
48
|
+
|
49
|
+
Dummy.new.csv_delete
|
50
|
+
end
|
16
51
|
end
|
17
52
|
|
18
|
-
|
19
|
-
|
53
|
+
context 'when local file does not exist' do
|
54
|
+
before do
|
55
|
+
stub_const 'Dummy', Class.new
|
56
|
+
|
57
|
+
Dummy.class_eval { include DataMigrater::CSV }
|
58
|
+
Dummy.class_eval { data_csv dir: 'missing/path' }
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'does not delete the file' do
|
62
|
+
expect(File).not_to receive(:delete)
|
20
63
|
|
21
|
-
|
64
|
+
Dummy.new.csv_delete
|
65
|
+
end
|
22
66
|
end
|
23
67
|
end
|
data/spec/csv/csv_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe '#data_csv' do
|
6
|
-
context 'when
|
6
|
+
context 'when has no provider' do
|
7
7
|
before do
|
8
8
|
stub_const 'Dummy', Class.new
|
9
9
|
|
@@ -39,6 +39,8 @@ RSpec.describe '#data_csv' do
|
|
39
39
|
|
40
40
|
allow(DataMigrater::S3).to receive(:new)
|
41
41
|
.with('data-migrater', {}, 'db/data_migrate/support/csv/dummy.csv').and_return double(download: true)
|
42
|
+
|
43
|
+
allow(File).to receive(:exist?).and_return true
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'reads csv from s3' do
|
@@ -47,4 +49,23 @@ RSpec.describe '#data_csv' do
|
|
47
49
|
Dummy.new.csv
|
48
50
|
end
|
49
51
|
end
|
52
|
+
|
53
|
+
context 'when file does not exist locally' do
|
54
|
+
before do
|
55
|
+
stub_const 'Dummy', Class.new
|
56
|
+
|
57
|
+
Dummy.class_eval { include DataMigrater::CSV }
|
58
|
+
Dummy.class_eval { data_csv dir: 'missing/path' }
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'does not process' do
|
62
|
+
expect(::SmarterCSV).not_to receive(:process)
|
63
|
+
|
64
|
+
Dummy.new.csv
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns an empty array' do
|
68
|
+
expect(Dummy.new.csv).to eq []
|
69
|
+
end
|
70
|
+
end
|
50
71
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_migrater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Washington Botelho
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-05-
|
12
|
+
date: 2019-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|