cranium 0.4.2 → 0.4.3

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,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5b878ec72b1afbd62b6d0c576653c4d5e5b1a0ee
4
- data.tar.gz: 41b765f1e0cf25648cf30cee548555b7f0ffaaaf
2
+ SHA256:
3
+ metadata.gz: 786956ff56304307aecdf21cd490af6c1bb1c116a87beff9ce7c8afb3935b329
4
+ data.tar.gz: 0aef7e4d5a467c7551f997a6f374448bf9cc2616afe1f20b929c0f6edc30e574
5
5
  SHA512:
6
- metadata.gz: b52aa636e49d51d48fc86397330527fe31c40214a055ef7c405befe1e5b53fe255064259de4857a57e0b8374ae111ce5e66a3d677878b010502f5d8faadc9f3d
7
- data.tar.gz: 98d0e5a309f127c50e7910c5510908dfb5e71a6f4f347f804c0118bb21a680bf45fb64b059b30866febb81e827dac8f65ea95a2830ea3826927d47e54f773c68
6
+ metadata.gz: 2175a36fc29efb510af186af5791973781856720dd065308a7d891cdd6e005174f74ecd500e2c5dc81b14d15bca512ad7fb3fd5fe334640328b3d305b48bb10e
7
+ data.tar.gz: 994c5aa959c1c32417814d68acf26b226949305a92297cdc20b90ef3be77efa7cfa77ec029c60843f5a1b223918df0c5508afa67d3843a0a537da065dcb89f3f
data/.env ADDED
@@ -0,0 +1 @@
1
+ DATABASE_HOST=127.0.0.1
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --require spec_helper
3
+ --order random
4
+ --fail-fast
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.5.1
data/README.md CHANGED
@@ -18,21 +18,9 @@ Or install it yourself as:
18
18
 
19
19
  ## Development
20
20
 
21
- start up the db
22
-
23
- docker-compose create && docker-compose start
24
-
25
- find out what's the ip is (in case you're using native docker)
26
-
27
- docker-compose ps
28
-
29
- (if using docker-machine use the machine's ip)
30
- setup the DATABASE_HOST enviroment variable to this IP (192.168.64.4 in my case)
31
-
32
- export DATABASE_HOST=192.168.64.4
33
-
34
- Now, your ready to run the integration tests :)
21
+ start up the db:
35
22
 
23
+ $ docker-compose up -d
36
24
 
37
25
  ## Contributing
38
26
 
data/cranium.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'cranium'
3
- spec.version = '0.4.2'
3
+ spec.version = '0.4.3'
4
4
  spec.authors = ['Emarsys Technologies']
5
5
  spec.email = ['smart-insight-dev@emarsys.com']
6
6
  spec.description = %q{Provides Extract, Transform and Load functionality for loading data from CSV files to a Greenplum database.}
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rspec', '~> 3'
24
24
  spec.add_development_dependency 'ruby-prof', '~> 0'
25
25
  spec.add_development_dependency 'cucumber', '~> 1'
26
+ spec.add_development_dependency 'dotenv', '~> 2.5'
26
27
  end
@@ -2,6 +2,7 @@ Feature: Archive source files
2
2
 
3
3
  Scenario:
4
4
  Given no "/tmp/cranium_archive" directory
5
+ And no "/tmp/cranium_storage" directory
5
6
  And a "products_1.csv" data file containing:
6
7
  """
7
8
  """
@@ -39,6 +40,8 @@ Feature: Archive source files
39
40
  end
40
41
 
41
42
  archive :products, :contacts
43
+
44
+ move :purchases, to: "/tmp/cranium_storage"
42
45
  """
43
46
  When I execute the definition
44
47
  Then the process should exit successfully
@@ -47,3 +50,6 @@ Feature: Archive source files
47
50
  | .*contacts.csv |
48
51
  | .*products_1.csv |
49
52
  | .*products_2.csv |
53
+ And the "/tmp/cranium_storage" directory should contain the following files:
54
+ | filename |
55
+ | purchases.csv |
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'dotenv/load'
2
3
  require_relative "../../lib/cranium"
3
4
 
4
5
  FileUtils.mkdir_p("log") unless Dir.exists?("log")
@@ -1,36 +1,37 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module Cranium::Archiver
4
-
5
- def self.archive(*files)
6
- create_archive_directory
7
- archive_files files
8
- end
9
-
10
-
11
-
12
- def self.remove(*files)
13
- files.each do |file_name|
14
- FileUtils.rm File.join(Cranium.configuration.upload_path, file_name)
4
+ class << self
5
+ def archive(*files)
6
+ create_directory(Cranium.configuration.archive_directory)
7
+ archive_datetime = Time.now.strftime("%Y-%m-%d_%Hh%Mm%Ss")
8
+ move_files_from_upload_directory(files, Cranium.configuration.archive_directory, prefix: "#{archive_datetime}_")
15
9
  end
16
- end
17
-
18
10
 
11
+ def remove(*files)
12
+ files.each do |file_name|
13
+ FileUtils.rm File.join(Cranium.configuration.upload_path, file_name)
14
+ end
15
+ end
19
16
 
20
- private
21
-
22
- def self.create_archive_directory
23
- FileUtils.mkpath Cranium.configuration.archive_directory unless Dir.exists? Cranium.configuration.archive_directory
24
- end
17
+ def move(*files, target_directory:)
18
+ create_directory(target_directory)
19
+ move_files_from_upload_directory(files, target_directory)
20
+ end
25
21
 
22
+ private
26
23
 
24
+ def create_directory(path)
25
+ FileUtils.mkdir_p(path)
26
+ end
27
27
 
28
- def self.archive_files(files)
29
- archive_datetime = Time.now.strftime("%Y-%m-%d_%Hh%Mm%Ss")
30
- files.each do |file_name|
31
- FileUtils.mv File.join(Cranium.configuration.upload_path, file_name),
32
- File.join(Cranium.configuration.archive_directory, "#{archive_datetime}_#{file_name}")
28
+ def move_files_from_upload_directory(files, target_directory, prefix: "")
29
+ files.each do |file_name|
30
+ FileUtils.mv(
31
+ File.join(Cranium.configuration.upload_path, file_name),
32
+ File.join(target_directory, "#{prefix}#{file_name}")
33
+ )
34
+ end
33
35
  end
34
36
  end
35
-
36
37
  end
data/lib/cranium/dsl.rb CHANGED
@@ -87,6 +87,14 @@ module Cranium::DSL
87
87
 
88
88
 
89
89
 
90
+ def move(*sources, to: "")
91
+ sources.each do |source_name|
92
+ Cranium::Archiver.move *Cranium.application.sources[source_name].files, target_directory: to
93
+ end
94
+ end
95
+
96
+
97
+
90
98
  def sequence(name)
91
99
  Cranium::Transformation::Sequence.new name
92
100
  end
@@ -22,8 +22,9 @@ class Cranium::TestFramework::World
22
22
 
23
23
 
24
24
  def save_definition(definition)
25
- config = <<-config_string
25
+ config = <<~config_string
26
26
  require 'logger'
27
+ require 'date'
27
28
 
28
29
  Cranium.configure do |config|
29
30
  config.greenplum_connection_string = "#{Cranium.configuration.greenplum_connection_string}"
@@ -32,6 +33,7 @@ class Cranium::TestFramework::World
32
33
  config.upload_directory = "#{Cranium.configuration.upload_directory}"
33
34
  config.loggers << Logger.new("log/application.log")
34
35
  end
36
+
35
37
  config_string
36
38
 
37
39
  upload_directory.save_file DEFINITION_FILE, config + definition
@@ -1,44 +1,72 @@
1
- require_relative '../spec_helper'
1
+ RSpec.describe Cranium::Archiver do
2
+ subject(:archiver) { described_class }
2
3
 
3
- describe Cranium::Archiver do
4
-
5
- before(:each) do
6
- allow(Cranium).to receive_messages(configuration: Cranium::Configuration.new.tap do |config|
7
- config.gpfdist_home_directory = "gpfdist_home"
8
- config.upload_directory = "upload_dir"
9
- config.archive_directory = "path/to/archive"
10
- end)
4
+ let(:configuration) do
5
+ Cranium::Configuration.new.tap do |config|
6
+ config.gpfdist_home_directory = "tmp"
7
+ config.upload_directory = "upload_directory"
8
+ config.archive_directory = "tmp/archive_directory"
9
+ end
11
10
  end
11
+ let(:file1) { "file.txt" }
12
+ let(:file2) { "another_file.txt" }
12
13
 
14
+ before do
15
+ allow(Cranium).to receive_messages(configuration: configuration)
16
+
17
+ FileUtils.mkdir_p(configuration.upload_path)
18
+ FileUtils.touch(File.join(configuration.upload_path, file1))
19
+ FileUtils.touch(File.join(configuration.upload_path, file2))
20
+ end
13
21
 
14
22
  describe ".archive" do
15
- it "should create the archive directory if it doesn't exist" do
16
- allow(Dir).to receive(:exists?).with("path/to/archive").and_return(false)
23
+ before { FileUtils.rm_rf configuration.archive_directory }
17
24
 
18
- expect(FileUtils).to receive(:mkpath).with "path/to/archive"
25
+ context "when archive directory does not exist" do
26
+ it "creates the archive directory" do
27
+ archiver.archive file1, file2
19
28
 
20
- Cranium::Archiver.archive
29
+ expect(File.exists?(configuration.archive_directory)).to eq true
30
+ end
21
31
  end
22
32
 
23
- it "should move files to the archive directory" do
24
- allow(Dir).to receive(:exists?).with("path/to/archive").and_return(true)
25
- allow(Time).to receive(:now).and_return Time.new(2000, 1, 1, 1, 2, 3)
33
+ context "when there are some file in the upload directory" do
34
+ it "moves files to the archive directory" do
35
+ archiver.archive file1, file2
26
36
 
27
- expect(FileUtils).to receive(:mv).with "gpfdist_home/upload_dir/file.txt", "path/to/archive/2000-01-01_01h02m03s_file.txt"
28
- expect(FileUtils).to receive(:mv).with "gpfdist_home/upload_dir/another_file.txt", "path/to/archive/2000-01-01_01h02m03s_another_file.txt"
29
-
30
- Cranium::Archiver.archive "file.txt", "another_file.txt"
37
+ expect(File.exist?(File.join(configuration.upload_path, file1))).to eq false
38
+ expect(File.exist?(File.join(configuration.upload_path, file2))).to eq false
39
+ expect(File.exist?(File.join(configuration.archive_directory, Dir.glob("*#{file1}")))).to eq true
40
+ expect(File.exist?(File.join(configuration.archive_directory, Dir.glob("*#{file2}")))).to eq true
41
+ end
31
42
  end
32
43
  end
33
44
 
34
-
35
45
  describe ".remove" do
36
- it "should remove files from the upload directory" do
37
- expect(FileUtils).to receive(:rm).with "gpfdist_home/upload_dir/file.txt"
38
- expect(FileUtils).to receive(:rm).with "gpfdist_home/upload_dir/another_file.txt"
46
+ it "removes files from the upload directory" do
47
+ archiver.remove file1, file2
39
48
 
40
- Cranium::Archiver.remove "file.txt", "another_file.txt"
49
+ expect(File.exist?(File.join(configuration.archive_directory, Dir.glob("*#{file1}")))).to eq true
50
+ expect(File.exist?(File.join(configuration.archive_directory, Dir.glob("*#{file2}")))).to eq true
41
51
  end
42
52
  end
43
53
 
54
+ describe ".move" do
55
+ let(:target_directory) { "tmp/target_directory" }
56
+
57
+ it "creates given directory if it does not exist" do
58
+ archiver.move(file1, file2, target_directory: target_directory)
59
+
60
+ expect(File.exists?(target_directory)).to eq true
61
+ end
62
+
63
+ it "moves files from upload directory into a given directory" do
64
+ archiver.move(file1, file2, target_directory: target_directory)
65
+
66
+ expect(File.exist?(File.join(configuration.upload_path, file1))).to eq false
67
+ expect(File.exist?(File.join(configuration.upload_path, file2))).to eq false
68
+ expect(File.exist?(File.join(target_directory, file1))).to eq true
69
+ expect(File.exist?(File.join(target_directory, file2))).to eq true
70
+ end
71
+ end
44
72
  end
@@ -97,6 +97,22 @@ describe Cranium::DSL do
97
97
  end
98
98
 
99
99
 
100
+ describe "#move" do
101
+ let(:target_directory) { "/tmp/target" }
102
+
103
+ it "should move files for the specified sources" do
104
+ allow(Cranium.application).to receive_messages sources: {first_source: double(files: ["file1", "file2"]),
105
+ second_source: double(files: ["file3"]),
106
+ third_source: double(files: ["file4"])}
107
+
108
+ expect(Cranium::Archiver).to receive(:move).with "file1", "file2", target_directory: target_directory
109
+ expect(Cranium::Archiver).to receive(:move).with "file3", target_directory: target_directory
110
+
111
+ dsl_object.move :first_source, :second_source, to: target_directory
112
+ end
113
+ end
114
+
115
+
100
116
  describe "#sequence" do
101
117
  it "should return a sequence with the specified name" do
102
118
  result = dsl_object.sequence "test_sequence"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cranium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emarsys Technologies
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-01 00:00:00.000000000 Z
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: dotenv
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.5'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.5'
139
153
  description: Provides Extract, Transform and Load functionality for loading data from
140
154
  CSV files to a Greenplum database.
141
155
  email:
@@ -145,7 +159,9 @@ executables:
145
159
  extensions: []
146
160
  extra_rdoc_files: []
147
161
  files:
162
+ - ".env"
148
163
  - ".gitignore"
164
+ - ".rspec"
149
165
  - ".ruby-version"
150
166
  - Gemfile
151
167
  - LICENSE.txt
@@ -297,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
313
  version: '0'
298
314
  requirements: []
299
315
  rubyforge_project:
300
- rubygems_version: 2.6.4
316
+ rubygems_version: 2.7.6
301
317
  signing_key:
302
318
  specification_version: 4
303
319
  summary: Pure Ruby ETL framework