From 30f2826bbb49fa6d18ba5a8b98c69aeeb984eb30 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Sun, 21 Apr 2013 18:06:02 +0300 Subject: Dont reimplement 'cmd', call #cmd from #get --- README.md | 2 +- lib/oxidized/input/cli.rb | 2 +- lib/oxidized/model/model.rb | 25 ++++++++----------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c42b42c..113941b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ # API ## Input * gets config from nodes - * must implement 'connect', 'get' + * must implement 'connect', 'get', 'cmd' * 'ssh' and 'telnet' implemented ## Output diff --git a/lib/oxidized/input/cli.rb b/lib/oxidized/input/cli.rb index 30a66f4..1d58e85 100644 --- a/lib/oxidized/input/cli.rb +++ b/lib/oxidized/input/cli.rb @@ -9,7 +9,7 @@ module Oxidized def get @post_login.each { |command| cmd command } - d = @node.model.cmds + d = @node.model.get disconnect d end diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb index a0717cf..fb27143 100644 --- a/lib/oxidized/model/model.rb +++ b/lib/oxidized/model/model.rb @@ -38,10 +38,12 @@ module Oxidized attr_accessor :input - def cmd string + def cmd string, &block out = @input.cmd string - out = cmd_all out - out = yield out if block_given? + self.class.cmds[:all].each do |all_block| + out = instance_exec out, &all_block + end + out = instance_exec out, &block if block out end @@ -53,13 +55,10 @@ module Oxidized self.class.prompt end - def cmds + def get data = '' - self.class.cmds[:cmd].each do |cmd, cmd_block| - out = @input.cmd cmd - out = cmd_all out - out = instance_exec out, &cmd_block if cmd_block - data << out.to_s + self.class.cmds[:cmd].each do |command, block| + data << (cmd command, &block).to_s end data << main.to_s if respond_to? :main data @@ -73,13 +72,5 @@ module Oxidized data end - private - - def cmd_all string - self.class.cmds[:all].each do |block| - string = instance_exec string, &block - end - string - end end end -- cgit v1.2.1