summaryrefslogtreecommitdiff
path: root/lib/oxidized/model/model.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2013-04-19 14:58:58 +0300
committerSaku Ytti <saku@ytti.fi>2013-04-19 14:58:58 +0300
commit5a393d6102655f575549311e6b250534b4dcbb59 (patch)
tree723ed044fd640b8f01615b2eb852f38346443f44 /lib/oxidized/model/model.rb
parent96668cc2dc0367e3d1a3ec94265ce889b62d8ada (diff)
Add 'cmd :all' convenience, ran after each command
Easier screen-scraping, if each command produces always same set of cruft that needs to be removed
Diffstat (limited to 'lib/oxidized/model/model.rb')
-rw-r--r--lib/oxidized/model/model.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb
index 6f02659..00a520d 100644
--- a/lib/oxidized/model/model.rb
+++ b/lib/oxidized/model/model.rb
@@ -2,7 +2,7 @@ module Oxidized
class Model
class << self
def inherited klass
- klass.instance_variable_set '@cmd', []
+ klass.instance_variable_set '@cmd', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@cfg', Hash.new { |h,k| h[k] = [] }
Oxidized.mgr.loader = { :class => klass }
end
@@ -22,7 +22,11 @@ module Oxidized
@cfg
end
def cmd _cmd=nil, &block
- @cmd << [_cmd, block]
+ if _cmd.class == Symbol
+ @cmd[_cmd] << block
+ else
+ @cmd[:cmd] << [_cmd, block]
+ end
end
def cmds
@cmd
@@ -50,9 +54,12 @@ module Oxidized
def cmds
data = ''
- self.class.cmds.each do |cmd, cb|
+ self.class.cmds[:cmd].each do |cmd, cmd_block|
out = @input.cmd cmd
- out = instance_exec out, &cb if cb
+ self.class.cmds[:all].each do |all_block|
+ out = instance_exec out, &all_block
+ end
+ out = instance_exec out, &cmd_block if cmd_block
data << out.to_s
end
data