tango 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  pkg/*
2
+ tmp/*
2
3
  *.gem
3
4
  .bundle
4
5
  .DS_Store
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tango (0.0.6)
4
+ tango (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -73,6 +73,44 @@ Running the Example
73
73
 
74
74
  tango example_installer.rb ExampleInstaller.install
75
75
 
76
+ Useful Helper Methods
77
+ ---------------------
78
+
79
+ ### Running Shell Commands
80
+
81
+ step "install something" do
82
+ result = shell("apt-get", "install", "something")
83
+ if result.succeeded?
84
+ write("/tmp/something-install.log", result.output)
85
+ end
86
+ end
87
+
88
+ ### Writing Config Files
89
+
90
+ step "configure foo" do
91
+ @log_directory = "/var/log/foo.log"
92
+ write "/etc/foo.conf", <<-EOF
93
+ # Config file for foo
94
+ log_file <%= @log_file %>
95
+ end
96
+ end
97
+
98
+ ### Changing the Working Directory
99
+
100
+ step "migrate" do
101
+ cd "/rails_apps/blog" do
102
+ shell "rake db:migrate"
103
+ end
104
+ end
105
+
106
+ ### Running As Another User
107
+
108
+ step "..." do
109
+ as "fred" do
110
+ FileUtils.touch("/home/fred/fred_woz_ere")
111
+ end
112
+ end
113
+
76
114
  Copyright
77
115
  ---------
78
116
 
@@ -0,0 +1,20 @@
1
+ require 'erb'
2
+
3
+ module Tango
4
+ module ConfigFiles
5
+
6
+ def write(path, contents)
7
+ contents = unindent(contents)
8
+ contents = ERB.new(contents).result(binding)
9
+ File.open(path, "w") {|file| file.write(contents) }
10
+ end
11
+
12
+ private
13
+
14
+ def unindent(text)
15
+ indent = /^ */.match(text)
16
+ text.gsub(/^#{indent}/, "")
17
+ end
18
+
19
+ end
20
+ end
@@ -1,14 +1,18 @@
1
1
  require 'tango/as_user'
2
+ require 'tango/config_files'
2
3
  require 'tango/delegate'
3
4
  require 'tango/met_and_meet'
4
5
  require 'tango/shell'
6
+ require 'tango/working_directory'
5
7
 
6
8
  module Tango
7
9
  class Runner
8
10
  include AsUser
11
+ include ConfigFiles
9
12
  include Delegate
10
13
  include MetAndMeet
11
14
  include Shell
15
+ include WorkingDirectory
12
16
 
13
17
  def self.step(step_name, &block)
14
18
  define_method(step_name) do |*args|
@@ -1,3 +1,3 @@
1
1
  module Tango
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,15 @@
1
+ module Tango
2
+ module WorkingDirectory
3
+
4
+ def cd(directory)
5
+ old_directory = Dir.getwd
6
+ begin
7
+ Dir.chdir(directory)
8
+ yield
9
+ ensure
10
+ Dir.chdir(old_directory)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ require 'tango'
2
+
3
+ module Tango
4
+ describe ConfigFiles do
5
+
6
+ before do
7
+ stub_class = Class.new do
8
+ include ConfigFiles
9
+
10
+ attr_accessor :world
11
+ end
12
+ @stub = stub_class.new
13
+
14
+ # Clear out the tmp directory before each test.
15
+ Dir.glob("tmp/*").each {|path| File.delete(path) }
16
+ end
17
+
18
+ it "should write a file" do
19
+ @stub.write("tmp/example.conf", "Hello, world!")
20
+ File.should exist("tmp/example.conf")
21
+ File.read("tmp/example.conf").should == "Hello, world!"
22
+ end
23
+
24
+ it "should overwrite an existing file" do
25
+ FileUtils.touch("tmp/example.conf")
26
+ @stub.write("tmp/example.conf", "Hello, world!")
27
+ File.read("tmp/example.conf").should == "Hello, world!"
28
+ end
29
+
30
+ it "should unindent contents before writing" do
31
+ @stub.write("tmp/example.conf", <<-EOF)
32
+ Goodbye
33
+ cruel
34
+ world!
35
+ EOF
36
+ File.read("tmp/example.conf").should == "Goodbye\n cruel\nworld!\n"
37
+ end
38
+
39
+ it "should render ERB in the contents" do
40
+ @stub.write("tmp/example.conf", "Hello, <%= 'world!' %>")
41
+ File.read("tmp/example.conf").should == "Hello, world!"
42
+ end
43
+
44
+ it "should allow access to instance variables in the ERB" do
45
+ @stub.world = "world!"
46
+ @stub.write("tmp/example.conf", "Hello, <%= @world %>")
47
+ File.read("tmp/example.conf").should == "Hello, world!"
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,57 @@
1
+ require 'tango'
2
+
3
+ module Tango
4
+ describe WorkingDirectory do
5
+
6
+ before do
7
+ stub_class = Class.new do
8
+ include WorkingDirectory
9
+ end
10
+ @stub = stub_class.new
11
+
12
+ # Make doubly sure we reset the working directory after each test.
13
+ @original_directory = Dir.getwd
14
+ end
15
+
16
+ after do
17
+ Dir.chdir(@original_directory)
18
+ end
19
+
20
+ it "should run a block" do
21
+ block_run = false
22
+ @stub.cd("/tmp") { block_run = true }
23
+ block_run.should be_true
24
+ end
25
+
26
+ it "should return the return value of the block" do
27
+ result = @stub.cd("/tmp") { "I woz ere." }
28
+ result.should == "I woz ere."
29
+ end
30
+
31
+ it "should change directory" do
32
+ directory = Dir.getwd + "/lib"
33
+ @stub.cd(directory) do
34
+ Dir.getwd.should == directory
35
+ end
36
+ end
37
+
38
+ it "should restore the original working directory" do
39
+ old_directory = Dir.getwd
40
+ directory = Dir.getwd + "/lib"
41
+ @stub.cd(directory) { }
42
+ Dir.getwd.should == old_directory
43
+ end
44
+
45
+ it "should restore the original directory after an exception" do
46
+ old_directory = Dir.getwd
47
+ directory = Dir.getwd + "/lib"
48
+ expect {
49
+ @stub.cd(directory) { raise "Uh oh!" }
50
+ }.should raise_error
51
+ Dir.getwd.should == old_directory
52
+ end
53
+
54
+ end
55
+ end
56
+
57
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tango
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pete Yandell
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-02 00:00:00 +11:00
18
+ date: 2011-04-11 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -52,16 +52,20 @@ files:
52
52
  - bin/tango
53
53
  - lib/tango.rb
54
54
  - lib/tango/as_user.rb
55
+ - lib/tango/config_files.rb
55
56
  - lib/tango/delegate.rb
56
57
  - lib/tango/logger.rb
57
58
  - lib/tango/met_and_meet.rb
58
59
  - lib/tango/runner.rb
59
60
  - lib/tango/shell.rb
60
61
  - lib/tango/version.rb
62
+ - lib/tango/working_directory.rb
63
+ - spec/config_files_spec.rb
61
64
  - spec/logger_spec.rb
62
65
  - spec/met_and_meet_spec.rb
63
66
  - spec/runner_spec.rb
64
67
  - spec/shell_spec.rb
68
+ - spec/working_directory_spec.rb
65
69
  - tango.gemspec
66
70
  has_rdoc: true
67
71
  homepage: ""
@@ -98,7 +102,9 @@ signing_key:
98
102
  specification_version: 3
99
103
  summary: Experiment in deployment tools.
100
104
  test_files:
105
+ - spec/config_files_spec.rb
101
106
  - spec/logger_spec.rb
102
107
  - spec/met_and_meet_spec.rb
103
108
  - spec/runner_spec.rb
104
109
  - spec/shell_spec.rb
110
+ - spec/working_directory_spec.rb