itiel 0.1.0 → 0.1.1
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 +4 -4
- data/lib/itiel/script/sql_script.rb +14 -10
- data/lib/itiel/version.rb +1 -1
- data/spec/script/sql_script_spec.rb +25 -19
- 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: 5bb7525bc6d55b9dec575c6ac77f7f525bfe0f19
|
4
|
+
data.tar.gz: 5acf8fb063e09eda1a6565d86ea2a45a58715dde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b142682959a000d16e93cf2e28ef75a423e7987a9ccfb24d4661c6db9d6b95b91eedc1531f680cf9b586404717593cebdbc88bd8d78445319127be5f4fbc628e
|
7
|
+
data.tar.gz: ea53fdacc0bfc10622f36b649584f911eeab5b93f606852ab3f47df924e755e5cb17b1c33acef5ee4b9313f1ee6b2533a91168a5f9e1fdea0bbb1d15db7a5d5e
|
@@ -8,21 +8,25 @@ module Itiel
|
|
8
8
|
include ChainedStep
|
9
9
|
include Itiel::DB::SQLConnectable
|
10
10
|
|
11
|
-
attr_accessor :connection
|
12
11
|
attr_accessor :sql
|
13
12
|
|
14
|
-
def initialize(
|
15
|
-
|
13
|
+
def initialize(sql=nil, &block)
|
14
|
+
if block_given?
|
15
|
+
self.sql = block
|
16
|
+
else
|
17
|
+
self.sql = sql
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
|
-
def execute(
|
21
|
+
def execute(input_stream=nil)
|
19
22
|
db = self.class.sequel_connection(connection)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
if input_stream.respond_to?(:each)
|
24
|
+
input_stream.each do |row|
|
25
|
+
db << sql.call(row)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
db << sql
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
data/lib/itiel/version.rb
CHANGED
@@ -2,40 +2,46 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Itiel::Script::SQLScript do
|
4
4
|
before :each do
|
5
|
-
@sql_script = Itiel::Script::SQLScript.new("DELETE FROM orders")
|
6
5
|
@data_stream = { "c" => "v" }
|
7
6
|
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
expect { @sql_script.sanity_check }.to raise_error Itiel::MissingConnection
|
13
|
-
end
|
8
|
+
context "with a string" do
|
9
|
+
before :each do
|
10
|
+
@sql_script = Itiel::Script::SQLScript.new("DELETE FROM orders")
|
14
11
|
end
|
15
12
|
|
16
|
-
describe
|
13
|
+
describe :execute do
|
17
14
|
before :each do
|
18
|
-
@
|
19
|
-
@sql_script.
|
15
|
+
@connection = double
|
16
|
+
@sql_script.connection = :test
|
17
|
+
allow(Itiel::Script::SQLScript).to receive(:sequel_connection).with(:test).and_return @connection
|
20
18
|
end
|
21
19
|
|
22
|
-
it "
|
23
|
-
expect
|
20
|
+
it "Executes the specified SQL script with the given connection" do
|
21
|
+
expect(@connection).to receive(:<<).with("DELETE FROM orders")
|
22
|
+
@sql_script.execute
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
|
27
|
+
context "with a block" do
|
29
28
|
before :each do
|
30
|
-
@
|
31
|
-
|
32
|
-
|
29
|
+
@sql_script = Itiel::Script::SQLScript.new do |row|
|
30
|
+
"DELETE FROM orders WHERE id = #{row[:id]}"
|
31
|
+
end
|
33
32
|
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
describe :execute do
|
35
|
+
before :each do
|
36
|
+
@connection = double
|
37
|
+
@sql_script.connection = :test
|
38
|
+
allow(Itiel::Script::SQLScript).to receive(:sequel_connection).with(:test).and_return @connection
|
39
|
+
end
|
40
|
+
|
41
|
+
it "Executes the specified SQL script with the given connection" do
|
42
|
+
expect(@connection).to receive(:<<).with("DELETE FROM orders WHERE id = 1")
|
43
|
+
@sql_script.execute([{ id: 1 }])
|
44
|
+
end
|
38
45
|
end
|
39
46
|
end
|
40
47
|
end
|
41
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itiel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Padilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|