tango 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tango (0.0.5)
4
+ tango (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 Envato & Pete Yandell.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.md CHANGED
@@ -10,36 +10,70 @@ that really don't fit with the way we want to use it at
10
10
  of Babushka's fundamentals to try to find a better fit.
11
11
 
12
12
 
13
- Example
14
- -------
13
+ Bootstrapping Ubuntu
14
+ --------------------
15
15
 
16
- class Homebrew < Tango::Namespace
17
- def installed?(formula)
18
- shell("brew", "info", formula, :echo => false).output !~ /Not installed/
16
+ sudo apt-get install -y ruby irb rdoc
17
+
18
+ # Use the real rubygems, not the silly apt version.
19
+ wget http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz
20
+ tar -zxvf rubygems-1.6.2.tgz
21
+ cd rubygems-1.6.2
22
+ sudo ruby setup.rb --no-format-executable
23
+
24
+ sudo gem install tango
25
+
26
+ Example Runner
27
+ --------------
28
+
29
+ class AptInstaller < Tango::Runner
30
+ def installed?(package)
31
+ shell("dpkg-query", "--status", package, :echo => false).output !~ /not.installed|deinstall/
19
32
  end
20
33
 
21
- step "bootstrap" do
22
- met? { shell("brew info").succeeded? }
23
- meet { shell(%{ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"}) }
34
+ step "install" do |package|
35
+ met? { installed?(package) }
36
+ # Need to figure out how to make this non-interactive. See:
37
+ # http://ubuntuforums.org/showthread.php?t=1218525
38
+ meet { shell("apt-get", "install", "-y", package) }
39
+ end
40
+ end
41
+
42
+ class GemInstaller < Tango::Runner
43
+ def installed?(gem)
44
+ shell("gem", "query", "--installed", "--name-matches", gem, :echo => false).output =~ /true/
24
45
  end
25
46
 
26
- step "install" do |formula|
27
- met? { installed?(formula) }
28
- meet { shell("brew, "install", formula) }
47
+ step "install" do |gem|
48
+ met? { installed?(gem) }
49
+ meet { shell("gem", "install", gem) }
29
50
  end
30
51
  end
31
52
 
32
- class MyNamespace < Tango::Namespace
33
- step "install" do
34
- Homebrew.run "bootstrap"
35
- Homebrew.run "install", "git"
36
- Homebrew.run "install", "mysql"
37
- run "install mtr"
53
+ class ExampleInstaller < Tango::Runner
54
+ def initialize
55
+ @apt = AptInstaller.new
56
+ @gem = GemInstaller.new
38
57
  end
39
58
 
40
- step "install mtr" do
41
- met? { Homebrew.installed?("mtr") }
42
- meet { shell("brew install --no-gtk mtr") }
59
+ step "install" do
60
+ @apt.install "build-essential"
61
+
62
+ @apt.install "mysql-server"
63
+ @apt.install "libmysqlclient-dev"
64
+
65
+ @apt.install "git-core"
66
+
67
+ @gem.install "bundler"
43
68
  end
44
69
  end
45
70
 
71
+ Running the Example
72
+ -------------------
73
+
74
+ tango example_installer.rb ExampleInstaller.install
75
+
76
+ Copyright
77
+ ---------
78
+
79
+ Copyright © 2011 Envato &amp; Pete Yandell. See LICENSE for details.
data/bin/tango CHANGED
@@ -7,4 +7,4 @@ load ARGV[0]
7
7
 
8
8
  namespace_name, step_name = ARGV[1].split(".")
9
9
 
10
- Object.const_get(namespace_name).run(step_name)
10
+ Object.const_get(namespace_name).new.run(step_name)
data/lib/tango.rb CHANGED
@@ -1,4 +1,2 @@
1
- require 'tango/as_user'
2
1
  require 'tango/logger'
3
- require 'tango/met_and_meet'
4
- require 'tango/namespace'
2
+ require 'tango/runner'
@@ -0,0 +1,24 @@
1
+ module Tango
2
+ module Delegate
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def delegate(*methods)
11
+ options = methods.pop
12
+ methods.each do |method|
13
+ define_method(method) do |*args|
14
+ send(options[:to]).send(method, *args)
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+
@@ -0,0 +1,40 @@
1
+ require 'tango/as_user'
2
+ require 'tango/delegate'
3
+ require 'tango/met_and_meet'
4
+ require 'tango/shell'
5
+
6
+ module Tango
7
+ class Runner
8
+ include AsUser
9
+ include Delegate
10
+ include MetAndMeet
11
+ include Shell
12
+
13
+ def self.step(step_name, &block)
14
+ define_method(step_name) do |*args|
15
+ description = step_description(step_name, args)
16
+
17
+ logger.enter(description)
18
+ result = instance_exec(*args, &block)
19
+ logger.leave(description)
20
+
21
+ result
22
+ end
23
+ end
24
+
25
+ def step_description(step_name, args)
26
+ description = "#{self.class.name}.#{step_name}"
27
+ description << "(" + args.map {|arg| arg.inspect }.join(", ") + ")" unless args.empty?
28
+ description
29
+ end
30
+
31
+ alias_method :run, :send
32
+
33
+ delegate :log, :log_raw, :to => :logger
34
+
35
+ def logger
36
+ Logger.instance
37
+ end
38
+
39
+ end
40
+ end
data/lib/tango/shell.rb CHANGED
@@ -14,6 +14,8 @@ module Tango
14
14
  Process.waitpid(pid)
15
15
  pipe.close
16
16
 
17
+ log "" if options[:echo]
18
+
17
19
  OpenStruct.new(
18
20
  :output => output,
19
21
  :status => $?.exitstatus,
data/lib/tango/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tango
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,37 +1,37 @@
1
1
  require 'tango'
2
2
 
3
- class StubLogger
3
+ class StubbedLogger
4
4
  def enter(name); end
5
5
  def leave(name); end
6
6
  def log(message); end
7
7
  end
8
8
 
9
- class StubbedNamespace < Tango::Namespace
10
- def self.logger
11
- @logger ||= StubLogger.new
9
+ class StubbedRunner < Tango::Runner
10
+ def logger
11
+ @logger ||= StubbedLogger.new
12
12
  end
13
13
  end
14
14
 
15
15
  module Tango
16
- describe Namespace do
16
+ describe Runner do
17
17
 
18
18
  it "should run a step" do
19
19
  step_run = false
20
20
 
21
- namespace = Class.new(StubbedNamespace) do
21
+ runner = Class.new(StubbedRunner) do
22
22
  step "example step" do
23
23
  step_run = true
24
24
  end
25
25
  end
26
26
 
27
- namespace.run "example step"
27
+ runner.new.run "example step"
28
28
  step_run.should be_true
29
29
  end
30
30
 
31
31
  it "should run one step from within another" do
32
32
  inner_step_run = false
33
33
 
34
- namespace = Class.new(StubbedNamespace) do
34
+ runner = Class.new(StubbedRunner) do
35
35
  step "outer step" do
36
36
  run "inner step"
37
37
  end
@@ -41,24 +41,24 @@ module Tango
41
41
  end
42
42
  end
43
43
 
44
- namespace.run "outer step"
44
+ runner.new.run "outer step"
45
45
  inner_step_run.should be_true
46
46
  end
47
47
 
48
48
  context "passing arguments" do
49
49
  it "should pass arguments to a step" do
50
- namespace = Class.new(StubbedNamespace) do
50
+ runner = Class.new(StubbedRunner) do
51
51
  step "example step" do |a, b|
52
52
  a.should == 1
53
53
  b.should == 2
54
54
  end
55
55
  end
56
56
 
57
- namespace.run "example step", 1, 2
57
+ runner.new.run "example step", 1, 2
58
58
  end
59
59
 
60
60
  it "should pass arguments when running other steps" do
61
- namespace = Class.new(StubbedNamespace) do
61
+ runner = Class.new(StubbedRunner) do
62
62
  step "outer step" do
63
63
  run "inner step", 1, 2
64
64
  end
@@ -69,7 +69,7 @@ module Tango
69
69
  end
70
70
  end
71
71
 
72
- namespace.run "outer step"
72
+ runner.new.run "outer step"
73
73
  end
74
74
  end
75
75
 
data/spec/shell_spec.rb CHANGED
@@ -33,8 +33,9 @@ module Tango
33
33
 
34
34
  it "should echo the command and its output" do
35
35
  @stub = @stub_class.new
36
- @stub.should_receive(:log).with("% echo Hello, world!\n\n")
37
- @stub.should_receive(:log_raw).with("Hello, world!\n")
36
+ @stub.should_receive(:log).with("% echo Hello, world!\n\n").once.ordered
37
+ @stub.should_receive(:log_raw).with("Hello, world!\n").once.ordered
38
+ @stub.should_receive(:log).with("").once.ordered
38
39
 
39
40
  @stub.shell("echo", "Hello, world!")
40
41
  end
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
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-01 00:00:00 +11:00
18
+ date: 2011-04-02 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,19 +46,21 @@ files:
46
46
  - .rspec
47
47
  - Gemfile
48
48
  - Gemfile.lock
49
+ - LICENSE
49
50
  - README.md
50
51
  - Rakefile
51
52
  - bin/tango
52
53
  - lib/tango.rb
53
54
  - lib/tango/as_user.rb
55
+ - lib/tango/delegate.rb
54
56
  - lib/tango/logger.rb
55
57
  - lib/tango/met_and_meet.rb
56
- - lib/tango/namespace.rb
58
+ - lib/tango/runner.rb
57
59
  - lib/tango/shell.rb
58
60
  - lib/tango/version.rb
59
61
  - spec/logger_spec.rb
60
62
  - spec/met_and_meet_spec.rb
61
- - spec/namespace_spec.rb
63
+ - spec/runner_spec.rb
62
64
  - spec/shell_spec.rb
63
65
  - tango.gemspec
64
66
  has_rdoc: true
@@ -98,5 +100,5 @@ summary: Experiment in deployment tools.
98
100
  test_files:
99
101
  - spec/logger_spec.rb
100
102
  - spec/met_and_meet_spec.rb
101
- - spec/namespace_spec.rb
103
+ - spec/runner_spec.rb
102
104
  - spec/shell_spec.rb
@@ -1,47 +0,0 @@
1
- require 'tango/as_user'
2
- require 'tango/met_and_meet'
3
- require 'tango/shell'
4
-
5
- module Tango
6
- class Namespace
7
- include AsUser
8
- include MetAndMeet
9
- include Shell
10
-
11
- def self.step(step_name, &block)
12
- define_method(step_name, &block)
13
- end
14
-
15
- def self.run(step_name, *args)
16
- description = "#{name}.#{step_name}"
17
- description << "(" + args.map {|arg| arg.inspect }.join(", ") + ")" unless args.empty?
18
-
19
- logger.enter(description)
20
- new.send(step_name, *args)
21
- logger.leave(description)
22
- end
23
-
24
- def run(step_name, *args)
25
- self.class.run(step_name, *args)
26
- end
27
-
28
- def log(message)
29
- self.class.logger.log(message)
30
- end
31
-
32
- def log_raw(message)
33
- self.class.logger.log_raw(message)
34
- end
35
-
36
- def self.method_missing(method, *args)
37
- new.send(method, *args)
38
- end
39
-
40
- private
41
-
42
- def self.logger
43
- Logger.instance
44
- end
45
-
46
- end
47
- end