runnable 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,88 +2,79 @@
2
2
  A Ruby gem that allow programmer to control UNIX system commands as a Ruby class.
3
3
 
4
4
  # Usage
5
- All you have to do is to create a class named exactly as command and make it inherit from class Runnable.
5
+ All you have to do is to create a class named exactly as command and make it
6
+ inherit from class Runnable.
6
7
 
7
- ```ruby
8
- class LS < Runnable
9
- end
10
- ```
8
+ class LS < Runnable
9
+ end
11
10
 
12
- That gives you the basics to control the execution of `ls` command.
11
+ That gives you the basics to control the execution of ```ls``` command.
13
12
 
14
13
  Now you can create an instance like this:
15
14
 
16
- ```ruby
17
- my_command = LS.new
18
- ```
15
+ my_command = LS.new
19
16
 
20
17
  And run the command as follows
21
18
 
22
- ```ruby
23
- my_command.run
24
- ```
19
+ my_command.run
25
20
 
26
21
  Many other options are available; you can stop the command, kill it or look
27
22
  for some important information about the command and its process. Entire
28
- documentation of this gem can be found under `./doc` directory or been generated
29
- by `yardoc`.
23
+ documentation of this gem can be generated using ```yardoc```. To do this use
24
+ ```rake doc```.
30
25
 
31
26
  ## Return values
32
- Runnable uses another gems called `Publisher`. It allow Runnable to fire
27
+ Runnable uses another gems called ```Publisher```. It allow Runnable to fire
33
28
  events that can be processed or ignored. When a command ends its execution,
34
- Runnable always fire and event: `:finish` if commands finalized in a correct way
35
- or `:fail` if an error ocurred. In case something went wrong and a `:fail`
29
+ Runnable always fire and event: ```:finish``` if commands finalized in a correct way
30
+ or ```:fail``` if an error ocurred. In case something went wrong and a ```:fail```
36
31
  events was fired, Runnable also provide an array containing the command return
37
32
  value as the parameter of a SystemCallError exception and optionally others
38
33
  exceptions ocurred at runtime.
39
34
 
40
35
  This is an example of how can we receive the return value of a command:
41
36
 
42
- ```ruby
43
- class LS < Runnable
44
- end
37
+ class LS < Runnable
38
+ end
45
39
 
46
- my_command = LS.new
40
+ my_command = LS.new
47
41
 
48
- my_command.when :finish do
49
- puts "Everything went better than expected :)"
50
- end
42
+ my_command.when :finish do
43
+ puts "Everything went better than expected :)"
44
+ end
51
45
 
52
- my_command.when :fail do |exceptions|
53
- puts "Something went wrong"
54
- exceptions.each do |exception|
55
- puts exception.message
56
- end
57
- end
46
+ my_command.when :fail do |exceptions|
47
+ puts "Something went wrong"
48
+ exceptions.each do |exception|
49
+ puts exception.message
50
+ end
51
+ end
58
52
 
59
- my_command.run
60
- ```
53
+ my_command.run
61
54
 
62
55
  ## Custom exceptions
63
56
  As we saw in previous chapter, if a command execution does not ends
64
- succesfully, Runnable fires a `:fail` event whit an exceptions array. We can
57
+ succesfully, Runnable fires a ```:fail``` event whit an exceptions array. We can
65
58
  add exceptions to that array based on the output of command. For example, we
66
59
  can controll that parameters passed to a command are valids if we know the
67
60
  command output for an invalid parameters.
68
61
 
69
- First we have to do is override the method `exceptions` defined in runnable
62
+ First we have to do is override the method ```exceptions``` defined in runnable
70
63
  as follows
71
64
 
72
- ```ruby
73
- class LS < Runnable
74
- def exceptions
75
- { /ls: (invalid option.*)/ => ArgumentError }
76
- end
77
- end
78
- ```
65
+ class LS < Runnable
66
+ def exceptions
67
+ { /ls: (invalid option.*)/ => ArgumentError }
68
+ end
69
+ end
79
70
 
80
- `exceptions` method should return a hash containing a regular expression
71
+ ```exceptions``` method should return a hash containing a regular expression
81
72
  which will be match against the command output, and a value which will be the
82
73
  exception added to exception array. This means that if the command output match
83
- the regular expression, a new exception will be include in `:fail` event parameter.
74
+ the regular expression, a new exception will be include in ```:fail``` event parameter.
84
75
 
85
76
  # About
86
- Runnable is a gem develop by [NoSoloSoftware](http://nosolosoftware.biz)
77
+ Runnable is a gem developed by [NoSoloSoftware](http://nosolosoftware.biz).
87
78
 
88
79
  # License
89
80
  Runnable is Copyright 2011 NoSoloSoftware, it is free software.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/runnable.rb CHANGED
@@ -16,6 +16,11 @@
16
16
  # along with Runnable. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
 
19
+ require 'runnable/gnu'
20
+ require 'runnable/extended'
21
+
22
+ require 'publisher'
23
+
19
24
  # Convert a executable command in a Ruby-like class
20
25
  # you are able to start, define params and send signals (like kill, or stop)
21
26
  #
@@ -27,11 +32,6 @@
27
32
  # ls = LS.new
28
33
  # ls.alh
29
34
  # ls.run
30
- #
31
- $LOAD_PATH << File.expand_path( './runnable', __FILE__ )
32
-
33
- require 'publisher'
34
-
35
35
  class Runnable
36
36
  extend Publisher
37
37
 
@@ -115,9 +115,7 @@ class Runnable
115
115
  @excep_array = []
116
116
 
117
117
 
118
- # Metaprogramming part
119
- # Require the class to parse the command line options
120
- require command_style.to_s.downcase
118
+ # Metaprogramming part
121
119
  # Create a new instance of the parser class
122
120
  @command_line_interface = Object.const_get( command_style.to_s.capitalize.to_sym ).new
123
121
  # End Metaprogramming part
@@ -139,8 +137,7 @@ class Runnable
139
137
  out_rd, out_wr = IO.pipe
140
138
  # Redirect Error I/O
141
139
  err_rd, err_wr = IO.pipe
142
-
143
- #
140
+
144
141
  @pid = Process.spawn( "#{@command} #{@input.join( " " )} \
145
142
  #{@options} #{@command_line_interface.parse} \
146
143
  #{@output.join( " " )}", { :out => out_wr, :err => err_wr } )
@@ -306,7 +303,6 @@ class Runnable
306
303
  # @param [Array] params Params in the call
307
304
  # @param [Block] block Block code in method
308
305
  # @return [nil]
309
- # @override
310
306
  def method_missing( method, *params, &block )
311
307
  if params.length > 1
312
308
  super( method, params, block )
@@ -16,10 +16,11 @@
16
16
  # along with Runnable. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
 
19
- # <p>Base class to create a command-line parameter parser.</p>
20
- # <p>It holds that parameters in a hash and the child has
19
+ # Base class to create a command-line parameter parser.
20
+ #
21
+ # It holds that parameters in a hash and the child has
21
22
  # to be the one who return the formatted string according
22
- # to the standard used.</p>
23
+ # to the standard used.
23
24
  class Command_parser
24
25
  # Create a new instance of the parser.
25
26
  def initialize
@@ -15,9 +15,9 @@
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with Runnable. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
- require 'command_parser'
18
+ require 'runnable/command_parser'
19
19
 
20
- # <p>Parse the parameter hash using the extended standard.</p>
20
+ # Parse the parameter hash using the extended standard.
21
21
  class Extended < Command_parser
22
22
 
23
23
  # Convert a hash in a Extended style string options.
data/lib/runnable/gnu.rb CHANGED
@@ -15,9 +15,9 @@
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with Runnable. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
- require 'command_parser'
18
+ require 'runnable/command_parser'
19
19
 
20
- # <p>Parse the parameter hash using the GNU standard.</p>
20
+ # Parse the parameter hash using the GNU standard.
21
21
  class Gnu < Command_parser
22
22
 
23
23
  # This method convert a hash in a string ready to
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: runnable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Rafael Garc\xC3\xADa"
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2011-05-05 00:00:00 Z
16
+ date: 2011-05-09 00:00:00 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: publisher
@@ -81,6 +81,17 @@ dependencies:
81
81
  type: :development
82
82
  prerelease: false
83
83
  version_requirements: *id006
84
+ - !ruby/object:Gem::Dependency
85
+ name: bluecloth
86
+ requirement: &id007 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: 2.1.0
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: *id007
84
95
  description: Convert a executable command in a Ruby-like class you are able to start, define params and send signals (like kill, or stop)
85
96
  email:
86
97
  - rgarcia@nosolosoftware.biz
@@ -114,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
125
  requirements:
115
126
  - - ">="
116
127
  - !ruby/object:Gem::Version
117
- hash: 1892356239618464581
128
+ hash: 2247934159745161744
118
129
  segments:
119
130
  - 0
120
131
  version: "0"