masamune 0.17.2 → 0.17.3

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: 539cdf75fd7e8734d5ad8393a80c1fe389ca1e52
4
- data.tar.gz: fea5c3e3908578febd63ac0a1e959c30442b5e09
3
+ metadata.gz: 308f642fba45cf0882c10023bcd0ab3f30a9a611
4
+ data.tar.gz: eb32061afd7d7e656bc0384eb1aeb694edebca90
5
5
  SHA512:
6
- metadata.gz: 06705c4e419adb0b2ffb82d35b80e92cfca1148f97c638880277f06d6f52731354915a9a3e468fdeec4f0874a5da7c6213660e5bc0df70e8ed5a104b3885d361
7
- data.tar.gz: b6c98cdbe32f2f83ce54835243da0c1f060f5dfca1500dd6366a99d3fb7b77e4f181b373dac32eb388d027840b796820e0979b71c03445f75d2520032a3d3966
6
+ metadata.gz: 657e6b91d3a6f09dc9d303d5c83e6fe0664ca92c5dfda40b828cf11d6bdfd2b6d870e70c010df328310d6afe46742df28df4dd84985eec1eb50e3f1ebbf16c7b
7
+ data.tar.gz: bc8f2e98fc05e9bb96096480f5a5070a6a386bb7911b430cb0ff7bfab80c905a6740402fd960fb833731822f16d2a147f2fc50ca1e22b3ccf0ee055e8851beb1
@@ -57,6 +57,7 @@ module Masamune::Commands
57
57
  DEFAULT_ATTRIBUTES.merge(configuration.hive).merge(attrs).each do |name, value|
58
58
  instance_variable_set("@#{name}", value)
59
59
  end
60
+ raise ArgumentError, 'Cannot specify both file and exec' if @file && @exec
60
61
  end
61
62
 
62
63
  def interactive?
@@ -86,7 +87,7 @@ module Masamune::Commands
86
87
  console("hive with file #{@file}")
87
88
  end
88
89
 
89
- if @debug and output = @rendered_file || @file
90
+ if @debug and output = rendered_template || @file
90
91
  logger.debug("#{output}:\n" + File.read(output))
91
92
  end
92
93
 
@@ -143,7 +144,7 @@ module Masamune::Commands
143
144
  end
144
145
 
145
146
  def command_args_for_file
146
- @file =~ /\.erb\Z/ ? command_args_for_template : command_args_for_simple_file
147
+ @command_args_for_file ||= (@file =~ /\.erb\Z/ ? command_args_for_template : command_args_for_simple_file)
147
148
  end
148
149
 
149
150
  def command_args_for_simple_file
@@ -156,8 +157,7 @@ module Masamune::Commands
156
157
  end
157
158
 
158
159
  def command_args_for_template
159
- @rendered_file = Masamune::Template.render_to_file(@file, @variables)
160
- filesystem.copy_file_to_file(@rendered_file, remote_file)
160
+ filesystem.copy_file_to_file(rendered_template, remote_file)
161
161
  ['-f', remote_file]
162
162
  end
163
163
 
@@ -173,5 +173,9 @@ module Masamune::Commands
173
173
  tmp.flush
174
174
  end.path
175
175
  end
176
+
177
+ def rendered_template
178
+ @rendered_template ||= Masamune::Template.render_to_file(@file, @variables)
179
+ end
176
180
  end
177
181
  end
@@ -55,6 +55,7 @@ module Masamune::Commands
55
55
  DEFAULT_ATTRIBUTES.merge(configuration.postgres).merge(attrs).each do |name, value|
56
56
  instance_variable_set("@#{name}", value)
57
57
  end
58
+ raise ArgumentError, 'Cannot specify both file and exec' if @file && @exec
58
59
  end
59
60
 
60
61
  def stdin
@@ -89,7 +90,7 @@ module Masamune::Commands
89
90
 
90
91
  def before_execute
91
92
  console("psql with file #{@file}") if @file
92
- if @debug and output = @rendered_file || @file
93
+ if @debug and output = rendered_template || @file
93
94
  logger.debug("#{output}:\n" + File.read(output))
94
95
  end
95
96
 
@@ -127,8 +128,7 @@ module Masamune::Commands
127
128
  end
128
129
 
129
130
  def command_args_for_template
130
- @rendered_file = Masamune::Template.render_to_file(@file, @variables)
131
- ['--file=%s' % @rendered_file]
131
+ ['--file=%s' % rendered_template]
132
132
  end
133
133
 
134
134
  def exec_file
@@ -137,5 +137,9 @@ module Masamune::Commands
137
137
  tmp.flush
138
138
  end.path
139
139
  end
140
+
141
+ def rendered_template
142
+ @rendered_template ||= Masamune::Template.render_to_file(@file, @variables)
143
+ end
140
144
  end
141
145
  end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Masamune
24
- VERSION = '0.17.2'
24
+ VERSION = '0.17.3'
25
25
  end
@@ -39,6 +39,7 @@ describe Masamune::Commands::Hive do
39
39
  allow(filesystem).to receive(:mktempdir!) { filesystem.path(:tmp_dir, mock_tmpdir) }
40
40
 
41
41
  allow(delegate).to receive(:filesystem) { filesystem }
42
+ allow(delegate).to receive(:logger).and_return(double)
42
43
  allow(delegate).to receive(:console).and_return(double)
43
44
  allow(delegate).to receive_message_chain(:configuration, :hive).and_return(configuration)
44
45
  end
@@ -71,6 +72,11 @@ describe Masamune::Commands::Hive do
71
72
  it { is_expected.to eq([*default_command, '-f', remote_file]) }
72
73
  end
73
74
 
75
+ context 'with file and exec' do
76
+ let(:attrs) { {file: local_file, exec: 'SELECT * FROM table;'} }
77
+ it { expect { instance }.to raise_error ArgumentError, 'Cannot specify both file and exec' }
78
+ end
79
+
74
80
  context 'with variables' do
75
81
  let(:attrs) { {file: local_file, variables: {R: 'R2DO', C: 'C3PO'}} }
76
82
  it { is_expected.to eq([*default_command, '-f', remote_file, '-d', 'R=R2DO', '-d', 'C=C3PO']) }
@@ -88,7 +94,18 @@ describe Masamune::Commands::Hive do
88
94
  context 'with template file' do
89
95
  let(:attrs) { {file: 'zomg.hql.erb'} }
90
96
  before do
91
- expect(Masamune::Template).to receive(:render_to_file).with('zomg.hql.erb', {}).and_return('XXX')
97
+ expect(Masamune::Template).to receive(:render_to_file).with('zomg.hql.erb', {}).and_return('zomg.hql')
98
+ expect_any_instance_of(Masamune::MockFilesystem).to receive(:copy_file_to_file)
99
+ end
100
+ it { is_expected.to eq([*default_command, '-f', filesystem.get_path(:tmp_dir, mock_tmpdir, 'zomg.hql')]) }
101
+ end
102
+
103
+ context 'with template file and debug' do
104
+ let(:attrs) { {file: 'zomg.hql.erb', debug: true} }
105
+ before do
106
+ expect(Masamune::Template).to receive(:render_to_file).with('zomg.hql.erb', {}).and_return('zomg.hql')
107
+ expect(File).to receive(:read).with('zomg.hql').and_return('SHOW TABLES;')
108
+ expect(instance.logger).to receive(:debug).with("zomg.hql:\nSHOW TABLES;")
92
109
  expect_any_instance_of(Masamune::MockFilesystem).to receive(:copy_file_to_file)
93
110
  end
94
111
  it { is_expected.to eq([*default_command, '-f', filesystem.get_path(:tmp_dir, mock_tmpdir, 'zomg.hql')]) }
@@ -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(:logger).and_return(double)
32
33
  allow(delegate).to receive(:console).and_return(double)
33
34
  allow(delegate).to receive_message_chain(:configuration, :postgres).and_return(configuration)
34
35
  end
@@ -75,6 +76,11 @@ describe Masamune::Commands::Postgres do
75
76
  it { is_expected.to eq([*default_command, '--file=zomg.psql']) }
76
77
  end
77
78
 
79
+ context 'with file and exec' do
80
+ let(:attrs) { {file: 'zomg.psql', exec: 'SELECT * FROM table;'} }
81
+ it { expect { subject }.to raise_error(/Cannot specify both file and exec/) }
82
+ end
83
+
78
84
  context 'with template file' do
79
85
  let(:attrs) { {file: 'zomg.psql.erb'} }
80
86
  before do
@@ -83,6 +89,16 @@ describe Masamune::Commands::Postgres do
83
89
  it { is_expected.to eq([*default_command, '--file=zomg.psql']) }
84
90
  end
85
91
 
92
+ context 'with template file and debug' do
93
+ let(:attrs) { {file: 'zomg.psql.erb', debug: true} }
94
+ before do
95
+ expect(Masamune::Template).to receive(:render_to_file).with('zomg.psql.erb', {}).and_return('zomg.psql')
96
+ expect(File).to receive(:read).with('zomg.psql').and_return('SHOW TABLES;')
97
+ expect(instance.logger).to receive(:debug).with("zomg.psql:\nSHOW TABLES;")
98
+ end
99
+ it { is_expected.to eq([*default_command, '--file=zomg.psql']) }
100
+ end
101
+
86
102
  context 'with variables and no file' do
87
103
  let(:attrs) { {variables: {R: 'R2D2', C: 'C3PO'}} }
88
104
  it { is_expected.to eq(default_command) }
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.17.2
4
+ version: 0.17.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Andrews
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor