diff options
Diffstat (limited to 'lib/oxidized/model/model.rb')
-rw-r--r-- | lib/oxidized/model/model.rb | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb index c3d8760..d3f54b9 100644 --- a/lib/oxidized/model/model.rb +++ b/lib/oxidized/model/model.rb @@ -1,3 +1,5 @@ +require_relative 'outputs' + module Oxidized class Model include Oxidized::Config::Vars @@ -77,17 +79,16 @@ module Oxidized def cmd string, &block out = @input.cmd string return false unless out - out = Oxidized::String.new out self.class.cmds[:all].each do |all_block| - out = instance_exec out, string, &all_block + out = instance_exec Oxidized::String.new(out), string, &all_block end if vars :remove_secret self.class.cmds[:secret].each do |all_block| - out = instance_exec out, string, &all_block + out = instance_exec Oxidized::String.new(out), string, &all_block end end - out = instance_exec out, &block if block - out + out = instance_exec Oxidized::String.new(out), &block if block + process_cmd_output out, string end def output @@ -124,20 +125,20 @@ module Oxidized end def get - data, pre = '', '' + outputs = Outputs.new procs = self.class.procs self.class.cmds[:cmd].each do |command, block| out = cmd command, &block return false unless out - data << out.to_s + outputs << out end procs[:pre].each do |pre_proc| - pre << instance_eval(&pre_proc).to_s + outputs.unshift Oxidized::String.new(instance_eval(&pre_proc)) end procs[:post].each do |post_proc| - data << instance_eval(&post_proc).to_s + outputs << Oxidized::String.new(instance_eval(&post_proc)) end - pre + data + outputs end def comment _comment @@ -148,5 +149,15 @@ module Oxidized data end + private + + def process_cmd_output output, name + if output.class != Oxidized::String + output = Oxidized::String.new output + end + output.set_cmd(name) + output + end + end end |