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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 319124d81efc2cd9b0963c9f1693862d7347170e
4
- data.tar.gz: 9e89b3071f090742e273d80a0023f703064f7325
3
+ metadata.gz: 5bb7525bc6d55b9dec575c6ac77f7f525bfe0f19
4
+ data.tar.gz: 5acf8fb063e09eda1a6565d86ea2a45a58715dde
5
5
  SHA512:
6
- metadata.gz: e4b71fb0ccdcec9e48cae895382e069b67680924b56901e034a10e6e452448081b2ea0fa5538e63e334ed2c15760dfa0143799795cbd753488fc72ba5b0d638f
7
- data.tar.gz: cc404b8fa1e0404e93caa8ab29d031a1496f7d74fe4440d55a524ff623d6cc6afc4ca62e87c19806ae18955768e14d1facb30728f0a41a4c1453f75fc0419620
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(*args)
15
- self.sql = args[0]
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
- db << sql
21
- end
22
-
23
- def sanity_check
24
- raise Itiel::MissingConnection unless self.connection
25
- raise Itiel::SQLSentenceNotProvided.new unless self.sql
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
@@ -1,3 +1,3 @@
1
1
  module Itiel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
- describe :sanity_check do
10
- describe "no connection specified" do
11
- it "raises Itiel::MissingConnection" do
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 "No SQL sentence is given" do
13
+ describe :execute do
17
14
  before :each do
18
- @sql_script.connection = Itiel::DB::Connection.new
19
- @sql_script.sql = nil
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 "raises Itiel::SQLSentenceNotProvided" do
23
- expect { @sql_script.sanity_check }.to raise_error Itiel::SQLSentenceNotProvided
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
- describe :execute do
27
+ context "with a block" do
29
28
  before :each do
30
- @connection = double
31
- @sql_script.connection = :test
32
- allow(Itiel::Script::SQLScript).to receive(:sequel_connection).with(:test).and_return @connection
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
- it "Executes the specified SQL script with the given connection" do
36
- expect(@connection).to receive(:<<).with(@sql_script.sql)
37
- @sql_script.execute
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.0
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-04-11 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport