dotanuki 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,7 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in dotanuki.gemspec
4
4
  gemspec
5
-
6
- group :test do
7
- gem "rspec"
8
- end
data/dotanuki.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency "popen4"
23
23
 
24
- #s.add_test_dependency "rspec"
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "metric_fu"
25
26
 
26
27
  end
data/lib/dotanuki.rb CHANGED
@@ -40,10 +40,17 @@ module Dotanuki
40
40
 
41
41
  def <<(result)
42
42
  raise ArgumentError unless result.is_a?(ExecResult)
43
+ # TODO merge correctly
43
44
  add(result.stdout, result.stderr, result.status)
44
45
  end
45
46
  end
46
47
 
48
+ def initialize(options={})
49
+ @defaults = {}
50
+ @defaults[:on_error] = :exception
51
+ @defaults.merge!(options)
52
+ end
53
+
47
54
  # Execute commands in a block and return an array of ExecResult
48
55
  #
49
56
  # @example
@@ -54,12 +61,15 @@ module Dotanuki
54
61
  #
55
62
  # TODO this is not thread safe
56
63
  def guard(options={}, &block)
64
+ opts = @defaults.merge(options)
65
+ validate_options(opts)
57
66
  @guard = ExecResult.new
58
67
  yield
59
68
  clear_guard
60
69
  rescue ExecError => e
61
- puts "guard on duty"
62
- clear_guard
70
+ result = clear_guard
71
+ raise e if opts[:on_error] == :exception
72
+ result
63
73
  end
64
74
 
65
75
  # commands can be a string or an array of strings
@@ -102,7 +112,7 @@ module Dotanuki
102
112
 
103
113
  def validate_options(options)
104
114
  options.each do |option, value|
105
- if option == :on_error && value != :exception
115
+ if option == :on_error && ! [:exception, :silent].include?(value)
106
116
  raise ArgumentError, "illegal value for option #{option}: #{value}"
107
117
  end
108
118
  raise ArgumentError, "illegal option: #{option}" if option != :on_error
@@ -1,3 +1,3 @@
1
1
  module Dotanuki
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -19,12 +19,24 @@ describe Dotanuki do
19
19
  end
20
20
 
21
21
  it "should stop when one item fails" do
22
- guard do
22
+ guard(:on_error => :silent) do
23
23
  execute("id")
24
24
  execute("ls /asd")
25
25
  execute("uname -n")
26
26
  end.failed_index.should == 1
27
27
  end
28
+
29
+ it "should raise an exception by default on error" do
30
+ lambda { guard do
31
+ execute("ls /asd")
32
+ end }.should raise_error
33
+ end
34
+
35
+ it "should not raise an exception by default on error" do
36
+ lambda { guard(:on_error => :silent) do
37
+ execute("ls /asd")
38
+ end }.should_not raise_error
39
+ end
28
40
  end
29
41
 
30
42
  describe "execute" do
metadata CHANGED
@@ -1,39 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dotanuki
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
4
5
  prerelease:
5
- version: 0.0.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Martin Englund
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-01 00:00:00 -07:00
12
+ date: 2011-06-02 00:00:00.000000000 -07:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: popen4
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2157101940 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
25
23
  type: :runtime
26
- version_requirements: *id001
27
- description: A command executioner which doesn't blindly stumble on when a command fails'
28
- email:
24
+ prerelease: false
25
+ version_requirements: *2157101940
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2157101500 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2157101500
37
+ - !ruby/object:Gem::Dependency
38
+ name: metric_fu
39
+ requirement: &2157100960 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2157100960
48
+ description: A command executioner which doesn't blindly stumble on when a command
49
+ fails'
50
+ email:
29
51
  - martin@englund.nu
30
52
  executables: []
31
-
32
53
  extensions: []
33
-
34
54
  extra_rdoc_files: []
35
-
36
- files:
55
+ files:
37
56
  - .autotest
38
57
  - .gitignore
39
58
  - .rspec
@@ -49,31 +68,28 @@ files:
49
68
  has_rdoc: true
50
69
  homepage: https://github.com/pmenglund/dotanuki
51
70
  licenses: []
52
-
53
71
  post_install_message:
54
72
  rdoc_options: []
55
-
56
- require_paths:
73
+ require_paths:
57
74
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
75
+ required_ruby_version: !ruby/object:Gem::Requirement
59
76
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
82
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
70
87
  requirements: []
71
-
72
88
  rubyforge_project: dotanuki
73
89
  rubygems_version: 1.6.2
74
90
  signing_key:
75
91
  specification_version: 3
76
92
  summary: Command executioner
77
- test_files:
93
+ test_files:
78
94
  - spec/dotanuki_spec.rb
79
95
  - spec/spec_helper.rb