soyuz 0.1.1 → 0.2.0

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: f0b3f776b8602c0188eac78cc5ad4fdbde9547e2
4
- data.tar.gz: c28b7bc7c6be22d1ee670d7537c08c09068c375c
3
+ metadata.gz: 59015ed20e3495f427c78b40f2846156ec4f5635
4
+ data.tar.gz: 8c25a79206d5a813d5b1f5507ae62de364d4fa60
5
5
  SHA512:
6
- metadata.gz: bae0502bb608b6cb73543f0036207e3aee10ae4ed448271fe0be9834ff28d77ed3bc210c804e89317878534a8e47aad147956d7ab09c9021cc549dc681ab8eac
7
- data.tar.gz: 7b451c9d74db0e2982dcd49d51772480098baa9b1be1571c81570d930745ac7569ffba9f90dd0430c61e26ba11ff661dc37dd18c619bee4c9259bdbe5db69bae
6
+ metadata.gz: 4d46c3f96343aa2da24b52830a4cac00250c11b299f9b10dbece7176252f898700196eaa6711cf5ae3de6e9329c9de2f455e8fe6cfb6dbd915dc433ae6b7b617
7
+ data.tar.gz: 3b398f211d1d670e8994a7c9a1237f3992aff052d5f358c783151731de5de9611a4077547f89a3f3cf19e9521325754cc87160b7b841b244e78b1c274c5f7ba6
data/CHANGELOG.markdown CHANGED
@@ -1 +1,6 @@
1
+ #### v0.2.0
2
+ * Adds the ability to set env variables for soyuz to use
3
+
4
+ > Nick LaMuro: Andy Fleener: https://github.com/sportngin/soyuz/pull/13
5
+
1
6
  #### v0.1.1
data/lib/soyuz/command.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'highline/import'
2
2
  require_relative 'command_choice'
3
+ require_relative 'command_env'
3
4
 
4
5
  module Soyuz
5
6
  class Command
@@ -10,7 +11,14 @@ module Soyuz
10
11
 
11
12
  def self.build(cmd)
12
13
  return if cmd.nil? || cmd.empty?
13
- cmd.is_a?(Array) ? CommandChoice.new(cmd) : new(cmd)
14
+
15
+ if cmd.is_a?(Array)
16
+ CommandChoice.new(cmd)
17
+ elsif cmd.is_a?(Hash)
18
+ CommandEnv.new(cmd)
19
+ else
20
+ new(cmd)
21
+ end
14
22
  end
15
23
 
16
24
  def run
@@ -13,7 +13,11 @@ module Soyuz
13
13
  say "#{index+1}) #{choice[:display]}"
14
14
  end
15
15
  choice = ask("? ", Integer) { |q| q.in = 1..@choices.length }
16
- Command.build(@choices[choice-1][:cmd]).run
16
+ build_command(choice-1)
17
+ end
18
+
19
+ def build_command(choice)
20
+ Command.build(@choices[choice][:cmd]).run
17
21
  end
18
22
  end
19
23
  end
@@ -0,0 +1,20 @@
1
+ require 'highline/import'
2
+
3
+ module Soyuz
4
+ class CommandEnv
5
+
6
+ NotHashMsg = "Environment Commands must be a Hash"
7
+ BadKeysMsg = "Environment Commands must contain :env_var and :env_val keys"
8
+
9
+ def initialize(cmd)
10
+ raise ArgumentError, NotHashMsg unless cmd.is_a?(Hash)
11
+ raise ArgumentError, BadKeysMsg unless cmd.has_key?(:env_var) && cmd.has_key?(:env_val)
12
+ @cmd = cmd
13
+ end
14
+
15
+ def run
16
+ ENV[@cmd[:env_var]] = @cmd[:env_val]
17
+ end
18
+
19
+ end
20
+ end
data/lib/soyuz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Soyuz
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,11 +2,12 @@ require "spec_helper"
2
2
  require "soyuz/command_choice"
3
3
  module Soyuz
4
4
  describe CommandChoice do
5
- let(:choices){ [{display: "choice1", cmd: "echo choice1"}, {display: "choice2", cmd: "echo choice2" }] }
6
- let(:command_double){ instance_double("Command", :run => true) }
5
+ let(:choices) { [{display: "choice1", cmd: "echo choice1"}, {display: "choice2", cmd: "echo choice2" }] }
6
+ let(:command_double) { instance_double("Command", :run => true) }
7
+
7
8
  subject { CommandChoice.new(choices) }
8
9
 
9
- context "choices isn't an array" do
10
+ describe "choices isn't an array" do
10
11
  let(:choices) { "I'm a command" }
11
12
  subject { CommandChoice }
12
13
  it "raises an error" do
@@ -14,29 +15,37 @@ module Soyuz
14
15
  end
15
16
  end
16
17
 
17
- context "#run" do
18
+ describe "#run" do
18
19
 
19
20
  it "creates a command for the given choice" do
20
21
  expect(subject).to receive(:say).with("1) choice1").once
21
22
  expect(subject).to receive(:say).with("2) choice2").once
22
23
  expect(subject).to receive(:ask).with(instance_of(String), Integer).and_return(1).once
23
- expect(Command).to receive(:build).with("echo choice1").and_return(command_double)
24
+ expect(subject).to receive(:build_command).with(0).once
24
25
  subject.run
25
26
  end
26
27
 
27
- context "Nested choices" do
28
+ end
29
+
30
+ describe "#build_command" do
31
+ context "with a single command" do
32
+ it "builds and runs the command" do
33
+ expect(Command).to receive(:build).with("echo choice1").and_return(command_double)
34
+ expect(command_double).to receive(:run)
35
+ subject.build_command(0)
36
+ end
37
+ end
38
+
39
+ context "with nested choices" do
28
40
  let(:nested_choices) { [{display: "choice1.1", cmd: "echo choice1.1"}, {display: "choice1.2", cmd: "echo choice1.2" }] }
29
41
  let(:choices){ [{display: "choice1", cmd: nested_choices }, {display: "choice2", cmd: "echo choice2" }] }
30
42
 
31
- it "creates a command for the given choice" do
32
- expect(subject).to receive(:say).with("1) choice1").once
33
- expect(subject).to receive(:say).with("2) choice2").once
34
- expect(subject).to receive(:ask).with(instance_of(String), Integer).and_return(1).once
43
+ it "builds and runs the commands" do
35
44
  expect(Command).to receive(:build).with(nested_choices).and_return(command_double)
36
- subject.run
45
+ expect(command_double).to receive(:run)
46
+ subject.build_command(0)
37
47
  end
38
48
  end
39
49
  end
40
-
41
50
  end
42
51
  end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ require "soyuz/command_env"
3
+
4
+ module Soyuz
5
+ describe CommandEnv do
6
+ let(:cmd){ { :env_var => "FOO", :env_val => "BAR" } }
7
+ subject { CommandEnv.new(cmd) }
8
+
9
+ before do
10
+ allow(subject).to receive(:puts)
11
+ end
12
+
13
+ it "sets the command" do
14
+ expect(subject.instance_variable_get(:@cmd)).to eq(cmd)
15
+ end
16
+
17
+ context "cmd isn't a hash" do
18
+ let(:cmd) { 1234 }
19
+ subject { CommandEnv }
20
+ it "raises an error" do
21
+ expect{ subject.new(cmd) }.to raise_error(ArgumentError, "Environment Commands must be a Hash")
22
+ end
23
+ end
24
+
25
+ context "cmd doesn't contain :env_var and :env_val" do
26
+ let(:cmd) { {} }
27
+ subject { CommandEnv }
28
+ it "raises an error" do
29
+ expect{ subject.new(cmd) }.to raise_error(ArgumentError, "Environment Commands must contain :env_var and :env_val keys")
30
+ end
31
+ end
32
+
33
+ describe "#run" do
34
+ before { @old_env = ENV.dup }
35
+
36
+ it "sets the environment_variable" do
37
+ subject.run
38
+ expect(ENV["FOO"]).to eq("BAR")
39
+ end
40
+
41
+ after { ENV = @old_env }
42
+ end
43
+ end
44
+ end
@@ -50,6 +50,16 @@ module Soyuz
50
50
  subject.build(cmd)
51
51
  end
52
52
  end
53
+
54
+ context "cmd is a env command" do
55
+ let(:cmd) { {:env_var => "FOO", :env_val => "BAR" } }
56
+ subject { Command }
57
+
58
+ it "sets the ENV based off of the :env_var and :env_val" do
59
+ expect(CommandEnv).to receive(:new).with(cmd)
60
+ subject.build(cmd)
61
+ end
62
+ end
53
63
  end
54
64
  end
55
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soyuz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Fleener
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -162,6 +162,7 @@ files:
162
162
  - lib/soyuz.rb
163
163
  - lib/soyuz/command.rb
164
164
  - lib/soyuz/command_choice.rb
165
+ - lib/soyuz/command_env.rb
165
166
  - lib/soyuz/config.rb
166
167
  - lib/soyuz/deploy.rb
167
168
  - lib/soyuz/environment.rb
@@ -170,6 +171,7 @@ files:
170
171
  - soyuz.gemspec
171
172
  - spec/files/soyuz_example.yml
172
173
  - spec/soyuz/command_choice_spec.rb
174
+ - spec/soyuz/command_env_spec.rb
173
175
  - spec/soyuz/command_spec.rb
174
176
  - spec/soyuz/config_spec.rb
175
177
  - spec/soyuz/deploy_spec.rb
@@ -203,6 +205,7 @@ summary: The old trusty deployment toolkit
203
205
  test_files:
204
206
  - spec/files/soyuz_example.yml
205
207
  - spec/soyuz/command_choice_spec.rb
208
+ - spec/soyuz/command_env_spec.rb
206
209
  - spec/soyuz/command_spec.rb
207
210
  - spec/soyuz/config_spec.rb
208
211
  - spec/soyuz/deploy_spec.rb