runnable 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +16 -18
- data/VERSION +1 -1
- data/lib/runnable.rb +19 -13
- data/runnable.gemspec +61 -0
- metadata +22 -32
data/README.markdown
CHANGED
@@ -24,32 +24,30 @@ documentation of this gem can be generated using ```yardoc```. To do this use
|
|
24
24
|
```rake doc```.
|
25
25
|
|
26
26
|
## Return values
|
27
|
-
Runnable
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
value as the parameter of a SystemCallError exception and optionally others
|
33
|
-
exceptions ocurred at runtime.
|
27
|
+
Runnable has two special methods which are called at the end of a command execution.
|
28
|
+
```:finish``` if commands finalized in a correct way and ```:fail``` if an error
|
29
|
+
ocurred. In case something went wrong and a ```:fail``` method is called, Runnable
|
30
|
+
also provide an array containing the command return value as the parameter of a
|
31
|
+
SystemCallError exception and optionally others exceptions ocurred at runtime.
|
34
32
|
|
35
|
-
This is an example of how can
|
33
|
+
This is an example of how we can receive the return value of a command:
|
36
34
|
|
37
35
|
class LS < Runnable
|
38
|
-
end
|
39
|
-
|
40
|
-
my_command = LS.new
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
def finish
|
38
|
+
puts "Everything went better than expected :)"
|
39
|
+
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
def failed( exceptions )
|
42
|
+
puts "Something went wrong :("
|
43
|
+
exceptions.each do |exception|
|
44
|
+
puts exception.message
|
45
|
+
end
|
50
46
|
end
|
47
|
+
|
51
48
|
end
|
52
49
|
|
50
|
+
my_command = LS.new
|
53
51
|
my_command.run
|
54
52
|
|
55
53
|
## Custom exceptions
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/runnable.rb
CHANGED
@@ -19,8 +19,6 @@
|
|
19
19
|
require 'runnable/gnu'
|
20
20
|
require 'runnable/extended'
|
21
21
|
|
22
|
-
require 'publisher'
|
23
|
-
|
24
22
|
# Convert a executable command in a Ruby-like class
|
25
23
|
# you are able to start, define params and send signals (like kill, or stop)
|
26
24
|
#
|
@@ -32,12 +30,7 @@ require 'publisher'
|
|
32
30
|
# ls = LS.new
|
33
31
|
# ls.alh
|
34
32
|
# ls.run
|
35
|
-
class Runnable
|
36
|
-
extend Publisher
|
37
|
-
|
38
|
-
# Fires to know whats happening inside
|
39
|
-
can_fire :fail, :finish
|
40
|
-
|
33
|
+
class Runnable
|
41
34
|
# Process id.
|
42
35
|
attr_reader :pid
|
43
36
|
# Process owner.
|
@@ -127,8 +120,6 @@ class Runnable
|
|
127
120
|
|
128
121
|
# Start the execution of the command.
|
129
122
|
# @return [nil]
|
130
|
-
# @fire :finish
|
131
|
-
# @fire :fail
|
132
123
|
def run
|
133
124
|
# Create a new mutex
|
134
125
|
@pid_mutex = Mutex.new
|
@@ -172,11 +163,11 @@ class Runnable
|
|
172
163
|
# In case of error add an Exception to the @excep_array
|
173
164
|
@excep_array << SystemCallError.new( exit_status ) if exit_status != 0
|
174
165
|
|
175
|
-
#
|
166
|
+
# Call methods according to the exit code
|
176
167
|
if @excep_array.empty?
|
177
|
-
|
168
|
+
finish
|
178
169
|
else
|
179
|
-
|
170
|
+
failed( @excep_array )
|
180
171
|
end
|
181
172
|
|
182
173
|
# This instance is finished and we remove it
|
@@ -343,6 +334,21 @@ class Runnable
|
|
343
334
|
{}
|
344
335
|
end
|
345
336
|
|
337
|
+
# @abstract
|
338
|
+
# Method called when command ends with no erros.
|
339
|
+
# This method is a hook so it should be overwritten in child classes.
|
340
|
+
# @return [nil]
|
341
|
+
def finish
|
342
|
+
end
|
343
|
+
|
344
|
+
# @abstract
|
345
|
+
# Method called when command executions fail.
|
346
|
+
# This method is a hook so it should be overwritten in child classes.
|
347
|
+
# @param [Array] exceptions Array containing exceptions raised during the command execution.
|
348
|
+
# @return [nil]
|
349
|
+
def failed( exceptions )
|
350
|
+
end
|
351
|
+
|
346
352
|
protected
|
347
353
|
|
348
354
|
# Send the desired signal to the command.
|
data/runnable.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{runnable}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Rafael García", "Luis Ciudad", "Pedro Navajas", "Javier Aranda"]
|
12
|
+
s.date = %q{2011-08-03}
|
13
|
+
s.description = %q{Convert a executable command in a Ruby-like class you are able to start, define params and send signals (like kill, or stop)}
|
14
|
+
s.email = ["rgarcia@nosolosoftware.biz", "lciudad@nosolosoftware.biz", "pnavajas@nosolosoftware.biz", "jaranda@nosolosoftware.biz"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.markdown"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"COPYING",
|
20
|
+
"README.markdown",
|
21
|
+
"VERSION",
|
22
|
+
"lib/runnable.rb",
|
23
|
+
"lib/runnable/command_parser.rb",
|
24
|
+
"lib/runnable/extended.rb",
|
25
|
+
"lib/runnable/gnu.rb",
|
26
|
+
"runnable.gemspec"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/nosolosoftware/runnable}
|
29
|
+
s.licenses = ["GPL-3"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.7.2}
|
32
|
+
s.summary = %q{A Ruby gem for execute and control system commands}
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
s.specification_version = 3
|
36
|
+
|
37
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
38
|
+
s.add_development_dependency(%q<rake>, [">= 0.8.7"])
|
39
|
+
s.add_development_dependency(%q<yard>, [">= 0.6.8"])
|
40
|
+
s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
|
41
|
+
s.add_development_dependency(%q<cucumber>, [">= 0.10.2"])
|
42
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.6.0"])
|
43
|
+
s.add_development_dependency(%q<bluecloth>, [">= 2.1.0"])
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
46
|
+
s.add_dependency(%q<yard>, [">= 0.6.8"])
|
47
|
+
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
48
|
+
s.add_dependency(%q<cucumber>, [">= 0.10.2"])
|
49
|
+
s.add_dependency(%q<jeweler>, [">= 1.6.0"])
|
50
|
+
s.add_dependency(%q<bluecloth>, [">= 2.1.0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
54
|
+
s.add_dependency(%q<yard>, [">= 0.6.8"])
|
55
|
+
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
56
|
+
s.add_dependency(%q<cucumber>, [">= 0.10.2"])
|
57
|
+
s.add_dependency(%q<jeweler>, [">= 1.6.0"])
|
58
|
+
s.add_dependency(%q<bluecloth>, [">= 2.1.0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: runnable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Rafael Garc\xC3\xADa"
|
@@ -13,85 +13,74 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2011-
|
16
|
+
date: 2011-08-03 00:00:00 Z
|
17
17
|
dependencies:
|
18
|
-
- !ruby/object:Gem::Dependency
|
19
|
-
name: publisher
|
20
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
-
none: false
|
22
|
-
requirements:
|
23
|
-
- - ~>
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version: 1.1.1
|
26
|
-
type: :runtime
|
27
|
-
prerelease: false
|
28
|
-
version_requirements: *id001
|
29
18
|
- !ruby/object:Gem::Dependency
|
30
19
|
name: rake
|
31
|
-
requirement: &
|
20
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
32
21
|
none: false
|
33
22
|
requirements:
|
34
|
-
- -
|
23
|
+
- - ">="
|
35
24
|
- !ruby/object:Gem::Version
|
36
25
|
version: 0.8.7
|
37
26
|
type: :development
|
38
27
|
prerelease: false
|
39
|
-
version_requirements: *
|
28
|
+
version_requirements: *id001
|
40
29
|
- !ruby/object:Gem::Dependency
|
41
30
|
name: yard
|
42
|
-
requirement: &
|
31
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
32
|
none: false
|
44
33
|
requirements:
|
45
|
-
- -
|
34
|
+
- - ">="
|
46
35
|
- !ruby/object:Gem::Version
|
47
36
|
version: 0.6.8
|
48
37
|
type: :development
|
49
38
|
prerelease: false
|
50
|
-
version_requirements: *
|
39
|
+
version_requirements: *id002
|
51
40
|
- !ruby/object:Gem::Dependency
|
52
41
|
name: rspec
|
53
|
-
requirement: &
|
42
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
43
|
none: false
|
55
44
|
requirements:
|
56
|
-
- -
|
45
|
+
- - ">="
|
57
46
|
- !ruby/object:Gem::Version
|
58
47
|
version: 2.5.0
|
59
48
|
type: :development
|
60
49
|
prerelease: false
|
61
|
-
version_requirements: *
|
50
|
+
version_requirements: *id003
|
62
51
|
- !ruby/object:Gem::Dependency
|
63
52
|
name: cucumber
|
64
|
-
requirement: &
|
53
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
54
|
none: false
|
66
55
|
requirements:
|
67
|
-
- -
|
56
|
+
- - ">="
|
68
57
|
- !ruby/object:Gem::Version
|
69
58
|
version: 0.10.2
|
70
59
|
type: :development
|
71
60
|
prerelease: false
|
72
|
-
version_requirements: *
|
61
|
+
version_requirements: *id004
|
73
62
|
- !ruby/object:Gem::Dependency
|
74
63
|
name: jeweler
|
75
|
-
requirement: &
|
64
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
76
65
|
none: false
|
77
66
|
requirements:
|
78
|
-
- -
|
67
|
+
- - ">="
|
79
68
|
- !ruby/object:Gem::Version
|
80
69
|
version: 1.6.0
|
81
70
|
type: :development
|
82
71
|
prerelease: false
|
83
|
-
version_requirements: *
|
72
|
+
version_requirements: *id005
|
84
73
|
- !ruby/object:Gem::Dependency
|
85
74
|
name: bluecloth
|
86
|
-
requirement: &
|
75
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
87
76
|
none: false
|
88
77
|
requirements:
|
89
|
-
- -
|
78
|
+
- - ">="
|
90
79
|
- !ruby/object:Gem::Version
|
91
80
|
version: 2.1.0
|
92
81
|
type: :development
|
93
82
|
prerelease: false
|
94
|
-
version_requirements: *
|
83
|
+
version_requirements: *id006
|
95
84
|
description: Convert a executable command in a Ruby-like class you are able to start, define params and send signals (like kill, or stop)
|
96
85
|
email:
|
97
86
|
- rgarcia@nosolosoftware.biz
|
@@ -112,6 +101,7 @@ files:
|
|
112
101
|
- lib/runnable/command_parser.rb
|
113
102
|
- lib/runnable/extended.rb
|
114
103
|
- lib/runnable/gnu.rb
|
104
|
+
- runnable.gemspec
|
115
105
|
homepage: http://github.com/nosolosoftware/runnable
|
116
106
|
licenses:
|
117
107
|
- GPL-3
|
@@ -125,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
115
|
requirements:
|
126
116
|
- - ">="
|
127
117
|
- !ruby/object:Gem::Version
|
128
|
-
hash:
|
118
|
+
hash: -4434214219882422992
|
129
119
|
segments:
|
130
120
|
- 0
|
131
121
|
version: "0"
|