masamune 0.15.1 → 0.15.2

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: 4dbe593ba3a215812769938a30319600a4d09dfd
4
- data.tar.gz: ce90762802dc54af83d0f82fd17cf17d86d79fcf
3
+ metadata.gz: b6b1e378ec9d528e71798e37eaf92a28e39ce275
4
+ data.tar.gz: a715c4524d5320cb579053f940419bfebd783036
5
5
  SHA512:
6
- metadata.gz: b4ed08a3d39df015ad02fc4b7957f5d507f071a953d21d7e3431b2ba204f64c9d727890563ca81722570c45b904cc8d99e977f27fc95baf2bb6197cc49f714d3
7
- data.tar.gz: f8105bc6cbdd055cbb897a7a4994d7c266dc4d258db006ae7f6fbe060fa0e0dfc45d83091a2b847c7159838fe474d682d43534938fef663cd93faa28a3f21929
6
+ metadata.gz: 5593ffbea50e048d74cf341afc34757a0e951df67528a7acdc5603a55fd2c4ed1c563ebebe3f396e41340af67d19ac9f9fcb5f3efb7ad03b902ea43a008bb602
7
+ data.tar.gz: 9b6cf17acce30109400902d6769ef72c90355542fa985e2b145e4a40aa9dd345f0054e17518f133d95ef950ba4e3e4f8975ce2eb0b0719a579eb1f9f6be95e92
@@ -83,7 +83,6 @@ module Masamune::Commands
83
83
  args << command_args_for_file if @file
84
84
  args << '--output=%s' % @output if @output
85
85
  args << '--no-align' << '--field-separator=,' << '--pset=footer' if @csv
86
- args << '--command=%s' % strip_sql(@exec) if @exec
87
86
  args << '--pset=tuples_only' if @tuple_output
88
87
  args.flatten.compact
89
88
  end
@@ -93,6 +92,11 @@ module Masamune::Commands
93
92
  if @debug and output = @rendered_file || @file
94
93
  logger.debug("#{output}:\n" + File.read(output))
95
94
  end
95
+
96
+ if @exec
97
+ console("postgres exec '#{strip_sql(@exec)}' #{'into ' + @output if @output}")
98
+ @file = exec_file
99
+ end
96
100
  end
97
101
 
98
102
  def handle_stdout(line, line_no)
@@ -126,5 +130,12 @@ module Masamune::Commands
126
130
  @rendered_file = Masamune::Template.render_to_file(@file, @variables)
127
131
  ['--file=%s' % @rendered_file]
128
132
  end
133
+
134
+ def exec_file
135
+ Tempfile.new('masamune').tap do |tmp|
136
+ tmp.write(@exec)
137
+ tmp.flush
138
+ end.path
139
+ end
129
140
  end
130
141
  end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Masamune
24
- VERSION = '0.15.1'
24
+ VERSION = '0.15.2'
25
25
  end
@@ -66,7 +66,7 @@ describe Masamune::Commands::Hive do
66
66
  context 'with exec' do
67
67
  let(:attrs) { {exec: 'SELECT * FROM table;'} }
68
68
  before do
69
- expect_any_instance_of(Masamune::MockFilesystem).to receive(:basename).and_return(File.basename(local_file))
69
+ expect(instance).to receive(:exec_file).and_return(remote_file)
70
70
  end
71
71
  it { is_expected.to eq([*default_command, '-f', remote_file]) }
72
72
  end
@@ -29,6 +29,7 @@ describe Masamune::Commands::Postgres do
29
29
  let(:instance) { described_class.new(delegate, attrs) }
30
30
 
31
31
  before do
32
+ allow(delegate).to receive(:console).and_return(double)
32
33
  allow(delegate).to receive_message_chain(:configuration, :postgres).and_return(configuration)
33
34
  end
34
35
 
@@ -50,6 +51,7 @@ describe Masamune::Commands::Postgres do
50
51
  let(:default_command) { ['psql', '--host=localhost', '--dbname=postgres', '--username=postgres', '--no-password', '--set=ON_ERROR_STOP=1'] }
51
52
 
52
53
  subject do
54
+ instance.before_execute
53
55
  instance.command_args
54
56
  end
55
57
 
@@ -60,17 +62,25 @@ describe Masamune::Commands::Postgres do
60
62
  it { is_expected.to eq([*default_command, '-A']) }
61
63
  end
62
64
 
65
+ context 'with exec' do
66
+ let(:attrs) { {exec: 'SELECT * FROM table;'} }
67
+ before do
68
+ expect(instance).to receive(:exec_file).and_return('zomg.psql')
69
+ end
70
+ it { is_expected.to eq([*default_command, '--file=zomg.psql']) }
71
+ end
72
+
63
73
  context 'with file' do
64
- let(:attrs) { {file: 'zomg.hql'} }
65
- it { is_expected.to eq([*default_command, '--file=zomg.hql']) }
74
+ let(:attrs) { {file: 'zomg.psql'} }
75
+ it { is_expected.to eq([*default_command, '--file=zomg.psql']) }
66
76
  end
67
77
 
68
78
  context 'with template file' do
69
- let(:attrs) { {file: 'zomg.hql.erb'} }
79
+ let(:attrs) { {file: 'zomg.psql.erb'} }
70
80
  before do
71
- expect(Masamune::Template).to receive(:render_to_file).with('zomg.hql.erb', {}).and_return('zomg.hql')
81
+ expect(Masamune::Template).to receive(:render_to_file).with('zomg.psql.erb', {}).and_return('zomg.psql')
72
82
  end
73
- it { is_expected.to eq([*default_command, '--file=zomg.hql']) }
83
+ it { is_expected.to eq([*default_command, '--file=zomg.psql']) }
74
84
  end
75
85
 
76
86
  context 'with variables and no file' do
@@ -79,8 +89,8 @@ describe Masamune::Commands::Postgres do
79
89
  end
80
90
 
81
91
  context 'with variables and file' do
82
- let(:attrs) { {file: 'zomg.hql', variables: {R: 'R2D2', C: 'C3PO'}} }
83
- it { is_expected.to eq([*default_command, '--file=zomg.hql', %q(--set=R='R2D2'), %q(--set=C='C3PO')]) }
92
+ let(:attrs) { {file: 'zomg.psql', variables: {R: 'R2D2', C: 'C3PO'}} }
93
+ it { is_expected.to eq([*default_command, '--file=zomg.psql', %q(--set=R='R2D2'), %q(--set=C='C3PO')]) }
84
94
  end
85
95
 
86
96
  context 'with csv' do
@@ -99,11 +99,7 @@ module Masamune::SharedExampleGroup
99
99
  end
100
100
 
101
101
  if input['psql']
102
- Tempfile.open('etl') do |tmp|
103
- tmp.write(input['psql'])
104
- tmp.flush
105
- postgres(file: tmp.path)
106
- end
102
+ postgres(exec: input['psql'])
107
103
  end
108
104
  end
109
105
  end
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.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Andrews
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor