Class: IscsiadmWrapper::Common
- Inherits:
-
Object
- Object
- IscsiadmWrapper::Common
- Defined in:
- lib/iscsiadm/common.rb
Class Method Summary collapse
-
.callout(cmd, filter, debug = false) ⇒ Object
Invoke an external program, passing each line of returned output through our filter.
-
.parse(line, filter) ⇒ Object
Convert match data to array, dropping the match all.
Class Method Details
.callout(cmd, filter, debug = false) ⇒ Object
Invoke an external program, passing each line of returned output through our filter.
Yield each all matches per line in block or return an array of all matches on every line.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/iscsiadm/common.rb', line 21 def callout(cmd, filter, debug=false) #:nodoc: puts "Executing `#{cmd}`" if debug ret = [] External::cmd(cmd) do |line| match = parse(line, filter) match.each do |t| ret << t end if defined? yield yield ret ret.clear end end ret end |
.parse(line, filter) ⇒ Object
Convert match data to array, dropping the match all. Returns an array of matches.
10 11 12 13 14 |
# File 'lib/iscsiadm/common.rb', line 10 def parse(line, filter) #:nodoc: match = filter.match(line).to_a match.shift match end |