Exit_Zero 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,11 +8,10 @@ Gem::Specification.new do |s|
8
8
  s.version = Exit_Zero::VERSION
9
9
  s.authors = ["da99"]
10
10
  s.email = ["i-hate-spam-45671204@mailinator.com"]
11
- s.homepage = "https://github.com/da99/Exit_Zero"
12
- s.summary = %q{Make sure your last child process exited with 0.}
11
+ s.homepage = "https://github.com/da99/Exit_0"
12
+ s.summary = %q{Obsolete. Use 'Exit_0' gem instead.}
13
13
  s.description = %q{
14
- A simple method that runs a child process and raises
15
- Exit_Zero::Non_Zero if $?.exitstatus is not zero.
14
+ Obsolete. Use gem 'Exit_0' instead.
16
15
  }
17
16
 
18
17
  s.files = `git ls-files`.split("\n")
@@ -27,6 +26,5 @@ Gem::Specification.new do |s|
27
26
 
28
27
  # s.rubyforge_project = "Exit_Zero"
29
28
  # specify any dependencies here; for example:
30
- s.add_runtime_dependency "Split_Lines"
31
- s.add_runtime_dependency "posix-spawn"
29
+ s.add_runtime_dependency "Exit_0"
32
30
  end
data/Gemfile CHANGED
@@ -4,4 +4,3 @@ source "http://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in Bob.gemspec
6
6
  gemspec
7
- gem 'open4'
data/README.md CHANGED
@@ -2,78 +2,5 @@
2
2
  Exit\_Zero
3
3
  =========
4
4
 
5
- A simple method that raises Exit\_Zero::Non\_Zero
6
- if $?.exitstatus is not zero.
7
-
8
- Don't like Exit\_Zero? Try:
9
-
10
- * [posix-spawn](https://github.com/rtomayko/posix-spawn).
11
- That is the easiest way to handle child processes
12
- (aka shelling out).
13
- * [POpen4](https://github.com/shairontoledo/popen4) Don't confuse it with regular popen4.
14
- * [Here are other alternatives](http://stackoverflow.com/questions/6338908/ruby-difference-between-exec-system-and-x-or-backticks).
15
-
16
- Windows
17
- ------
18
-
19
- Use something else. Check the previous list above
20
- for other alternatives,
21
- especialy [POpen4](https://github.com/shairontoledo/popen4),
22
- which is Windows and POSIX compatible.
23
-
24
- Implementation
25
- ----
26
-
27
- Exit\_Zero runs your command through bash:
28
-
29
- your command: uptime
30
- Final result: POSIX::Spawn::Child.new "bash -lc #{cmd.inspect}"
31
-
32
- Exit\_Zero lives in one file. So if you have any questions, [here
33
- it is](https://github.com/da99/Exit\_Zero/blob/master/lib/Exit\_Zero.rb).
34
-
35
-
36
- Installation
37
- ------------
38
-
39
- gem install Exit_Zero
40
-
41
- Usage
42
- ------
43
-
44
- require "Exit_Zero"
45
-
46
- Exit_Zero 'uptime'
47
- Exit_Zero 'ls', :input=>' /some/dir '
48
- Exit_Zero { system "uptime" }
49
-
50
- # The following raises an error.
51
- Exit_Zero 'uptimeSS'
52
- Exit_Zero { `uptimeSSS` }
53
-
54
- # Exit_0 and Exit_Zero are the same.
55
- Exit_0 'uptime'
56
- Exit_0 'grep a', :input=>"a \n b \n c"
57
-
58
- # Get results from standard output, standard error.
59
- Exit_0('uptime').out # String is stripped.
60
- Exit_0('uptimeSS').err # String is stripped.
61
-
62
- Exit_0('uptime').raw_out # Raw string, no :strip used.
63
- Exit_0('uptime').raw_err # Raw string, no :strip used.
64
-
65
- Run Tests
66
- ---------
67
-
68
- git clone git@github.com:da99/Exit_Zero.git
69
- cd Exit_Zero
70
- bundle update
71
- bundle exec bacon spec/main.rb
72
-
73
- "I hate writing."
74
- -----------------------------
75
-
76
- If you know of existing software that makes the above redundant,
77
- please tell me. The last thing I want to do is maintain code.
78
-
79
-
5
+ Obsolete. The name of this gem has been changed to
6
+ Exit\_0. [Github project for Exit\_0](https://github.com/da99/Exit_0).
@@ -1,90 +1,2 @@
1
- require 'Exit_Zero/version'
2
- require 'Split_Lines'
3
- require 'posix/spawn'
4
1
 
5
- def Exit_Zero *cmd, &blok
6
-
7
- both = !cmd.empty? && block_given?
8
- raise ArgumentError, "Both command and block are not allowed." if both
9
-
10
- if block_given?
11
- cmd = blok
12
- r = p = blok.call
13
- msg = cmd
14
- else
15
- r = p = Exit_Zero::Child.new(*cmd)
16
- msg = p.err.strip.empty? ? p.cmd : p.err
17
- msg << " (command: #{cmd})"
18
- end
19
-
20
-
21
- (r = r.status) if r.respond_to?(:status)
22
- raise(Exit_Zero::Unknown_Exit, msg.inspect) unless r.respond_to?(:exitstatus)
23
- raise(Exit_Zero::Non_Zero, "#{r.exitstatus} => #{msg}") if r.exitstatus != 0
24
-
25
- p
26
- end # === Exit_Zero
27
-
28
- def Exit_0 *cmd, &blok
29
- Exit_Zero *cmd, &blok
30
- end
31
-
32
- class Exit_Zero
33
-
34
- Non_Zero = Class.new(RuntimeError)
35
- Unknown_Exit = Class.new(RuntimeError)
36
-
37
- module Class_Methods
38
- end # === Class_Methods
39
-
40
- extend Class_Methods
41
-
42
- class Child
43
- module Base
44
-
45
- attr_reader :cmd, :child
46
- def initialize *cmd
47
- if cmd[0].is_a?(String)
48
-
49
- if cmd[0]["\n"]
50
- cmd[0] = begin
51
- cmd[0]
52
- .split("\n")
53
- .map(&:strip)
54
- .reject(&:empty?)
55
- .join(" && ")
56
- end
57
- end
58
-
59
- cmd[0] = "bash -lc #{cmd[0].inspect}"
60
-
61
- end
62
- @child = POSIX::Spawn::Child.new(*cmd)
63
- @cmd = cmd.join(' ')
64
- end
65
-
66
- def split_lines
67
- Split_Lines(child.out)
68
- end
69
-
70
- %w{ out err }.each { |m|
71
- eval %~
72
- def raw_#{m}
73
- child.#{m}
74
- end
75
-
76
- def #{m}
77
- child.#{m}.strip
78
- end
79
- ~
80
- }
81
-
82
- def status
83
- child.status
84
- end
85
-
86
- end # === Base
87
- include Base
88
- end # === Child
89
-
90
- end # === class Exit_Zero
2
+ require 'Exit_0'
@@ -1,3 +1,3 @@
1
1
  class Exit_Zero
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -1,102 +1,9 @@
1
-
2
- describe "Exit_Zero *cmd" do
3
-
4
- it "accepts the same arguments as POSIX::Spawn::Child" do
5
- Exit_Zero("dc", :input=>'4 4 + p').out
6
- .should == "8"
7
- end
8
-
9
- it "raises Exit_Zero::Non_Zero if command exits with non-zero" do
10
- lambda {
11
- Exit_Zero 'uptimes'
12
- }.should.raise(Exit_Zero::Non_Zero)
13
- .message.should.match %r!127 => bash: uptimes: command not found!
14
- end
15
-
16
- it "returns a Exit_Zero::Child" do
17
- Exit_Zero('whoami').class.should.be == Exit_Zero::Child
18
- end
19
-
20
- it "executes valid command" do
21
- Exit_Zero('pwd').out.should == `pwd`.strip
22
- end
23
-
24
- it "raises ArgumentError if both a cmd and block are given" do
25
- lambda { Exit_Zero('uptime') {} }
26
- .should.raise(ArgumentError)
27
- .message.should.match %r!are not allowed!i
28
- end
29
-
30
- it "combines a multi-line string into one string, joined by \"&&\"" do
31
- Exit_Zero(%!
32
- cd ~/
33
- pwd
34
- !)
35
- .out.should == `cd ~/ && pwd`.strip
36
- end
37
-
38
- it "ignores empty lines in a multi-line string" do
39
- Exit_Zero(%!
40
- cd ~/
41
-
42
- pwd
43
- !).out.should == `cd ~/ && pwd`.strip
44
- end
45
-
46
- end # === Exit_Zero 'cmd'
47
-
48
- describe "Exit_Zero { }" do
49
-
50
- it "returns last value of the block" do
51
- Exit_Zero{ POSIX::Spawn::Child.new("ls ~") }
52
- .out.should. == `ls ~`
53
- end
54
-
55
- it "raises Exit_Zero::Non_Zero if return value has exitstatus != 0" do
56
- b = lambda { POSIX::Spawn::Child.new("something_not_found") }
57
- lambda {
58
- Exit_Zero(&b)
59
- }.should.raise(Exit_Zero::Non_Zero)
60
- .message.should == "127 => #{b.inspect}"
61
- end
1
+ describe "Exit_Zero" do
62
2
 
63
- it "raise Unknown_Exit if block return value does not respond to :status and :exitstatus" do
64
- target = lambda { :a }
65
- lambda {
66
- Exit_Zero(&target)
67
- }.should.raise(Exit_Zero::Unknown_Exit)
68
- .message.should.match %r!#{Regexp.escape target.inspect}!
3
+ it "accepts the same arguments as Exit_0" do
4
+ Exit_Zero("grep a", :input=>"a\nb\nc")
5
+ .out.should == "a"
69
6
  end
70
7
 
71
- end # === Exit_Zero { }
72
-
73
- describe "Exit_Zero::Child" do
74
-
75
- # ---- :out
76
-
77
- it "returns stripped :out" do
78
- Exit_Zero::Child.new("pwd").out
79
- .should == `pwd`.strip
80
- end
81
-
82
- it "returns raw output for :raw_out" do
83
- Exit_Zero::Child.new("pwd").raw_out
84
- .should == `pwd`
85
- end
86
-
87
- # ---- :err
88
-
89
- it "returns stripped :err" do
90
- Exit_Zero::Child.new("pwdssssss").err
91
- .should == `bash -lc "pwdssssss" 2>&1`.strip
92
- end
93
-
94
- it "returns raw output for :raw_out" do
95
- Exit_Zero::Child.new("no_exist").err
96
- .should.match %r!no_exist: command not found!
97
- end
98
-
99
- end # === Exit_Zero::Child
100
-
101
-
8
+ end # === Exit_Zero
102
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Exit_Zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-17 00:00:00.000000000 Z
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon
@@ -76,7 +76,7 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: Split_Lines
79
+ name: Exit_0
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -91,24 +91,7 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: posix-spawn
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- description: ! "\n A simple method that runs a child process and raises\n Exit_Zero::Non_Zero
111
- if $?.exitstatus is not zero.\n "
94
+ description: ! "\n Obsolete. Use gem 'Exit_0' instead.\n "
112
95
  email:
113
96
  - i-hate-spam-45671204@mailinator.com
114
97
  executables: []
@@ -124,11 +107,8 @@ files:
124
107
  - lib/Exit_Zero/version.rb
125
108
  - spec/helper.rb
126
109
  - spec/main.rb
127
- - spec/tests/Child.rb
128
- - spec/tests/Exit_0.rb
129
110
  - spec/tests/Exit_Zero.rb
130
- - spec/tests/bin.rb
131
- homepage: https://github.com/da99/Exit_Zero
111
+ homepage: https://github.com/da99/Exit_0
132
112
  licenses: []
133
113
  post_install_message:
134
114
  rdoc_options: []
@@ -148,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
128
  version: '0'
149
129
  requirements: []
150
130
  rubyforge_project:
151
- rubygems_version: 1.8.19
131
+ rubygems_version: 1.8.23
152
132
  signing_key:
153
133
  specification_version: 3
154
- summary: Make sure your last child process exited with 0.
134
+ summary: Obsolete. Use 'Exit_0' gem instead.
155
135
  test_files: []
@@ -1,31 +0,0 @@
1
- describe "Child.new" do
2
-
3
- it 'executes given string' do
4
- Exit_Zero::Child.new("pwd").raw_out.should == `pwd`
5
- end
6
-
7
- end # === Exit_Zero::Child
8
-
9
- describe "Child#split_lines" do
10
-
11
- it "returns split lines of output through :split_lines" do
12
- r = Exit_Zero::Child.new('ls -Al')
13
- r.split_lines.should == `ls -Al`.strip.split("\n")
14
- end
15
-
16
- end # === Child#split_lines
17
-
18
- describe "Child delegate methods" do
19
-
20
- %w{ raw_out raw_err status }.each { |m|
21
- o_m = m.sub("raw_", '')
22
- it "sets :#{m} equal to Child :#{o_m}" do
23
- cmd = %q! ruby -e "puts 'a'; warn 'b'; exit(127);"!
24
- target = POSIX::Spawn::Child.new(cmd)
25
- Exit_Zero::Child.new(cmd)
26
- .send(m).should == target.send(o_m)
27
- end
28
- }
29
-
30
- end # === Child delegate methods
31
-
@@ -1,9 +0,0 @@
1
- describe "Exit_0" do
2
-
3
- it "accepts the same arguments as Exit_Zero" do
4
- Exit_0("grep a", :input=>"a\nb\nc")
5
- .out.should == "a"
6
- end
7
-
8
- end # === Exit_0
9
-
@@ -1,10 +0,0 @@
1
-
2
- describe "permissions of bin/" do
3
-
4
- it "should be 750" do
5
- `stat -c %a bin`.strip
6
- .should.be == "750"
7
- end
8
-
9
- end # === permissions of bin/
10
-