platform_simulation_specs/common/ohai_plugin_common.rb
def read_output( cmd, path = "#{data_path}" )

    #using an anonymous class to minimize scoping issues.
    @data = Class.new do
      @instances

      #DSL - make a list of hashes with
      def push(param, value)
        @instances ||= []
        @instances[0] ||= {}
        current = {}
        current = @instances.pop if @instances.last[param].nil?
        current[param] = value
        @instances << current
      end
      @methods = [:platform, :arch, :env, :params, :stdout, :stderr, :exit_status]
      @methods.each { |m| self.send(:define_method, m.to_s) { |text| push m.to_sym, text }}

      #Format data into a form the rest of the app expects
      def process
        data = {}

        @instances ||= []

        @instances.each do |i|
          data[i[:platform]] ||= {}
          data[i[:platform]][i[:arch]] ||= []
          data[i[:platform]][i[:arch]] << i.reject { |k,v| k == :platform || k == :arch }
        end
        data
      end
    end

    @data = @data.new
    @data.instance_eval( File.read( "#{path}/#{cmd}.output" ))
    @data.process
  end
# read in the data file for fake executables
read in the data file for fake executables
read in the data file for fake executables
def read_output( cmd, path = "#{data_path}" )
    @data = Class.new do
      @instances
      def push(param, value)
        @instances ||= []
        @instances[0] ||= {}
        current = {}
        current = @instances.pop if @instances.last[param].nil?
        current[param] = value
        @instances << current
      end
      @methods = [:platform, :arch, :env, :params, :stdout, :stderr, :exit_status]
      @methods.each { |m| self.send(:define_method, m.to_s) { |text| push m.to_sym, text }}
      def process
        data = {}
        @instances ||= []
        @instances.each do |i|
          data[i[:platform]] ||= {}
          data[i[:platform]][i[:arch]] ||= []
          data[i[:platform]][i[:arch]] << i.reject { |k,v| k == :platform || k == :arch }
        end
        data
      end
    end
    @data = @data.new
    @data.instance_eval( File.read( "#{path}/#{cmd}.output" ))
    @data.process
  end
def read_output ( cmd , path = "#{data_path}" ) @data = Class . new do @instances def push ( param , value ) @instances ||= [ ] @instances [ 0 ] ||= { } current = { } current = @instances . pop if @instances . last [ param ] . nil? current [ param ] = value @instances << current end @methods = [ :platform , :arch , :env , :params , :stdout , :stderr , :exit_status ] @methods . each { | m | self . send ( :define_method , m . to_s ) { | text | push m . to_sym , text } } def process data = { } @instances ||= [ ] @instances . each do | i | data [ i [ :platform ] ] ||= { } data [ i [ :platform ] ] [ i [ :arch ] ] ||= [ ] data [ i [ :platform ] ] [ i [ :arch ] ] << i . reject { | k , v | k == :platform || k == :arch } end data end end @data = @data . new @data . instance_eval ( File . read ( "#{path}/#{cmd}.output" ) ) @data . process end
read in the data file for fake executables
read in the data file for fake executables
#using an anonymous class to minimize scoping issues. #DSL - make a list of hashes with #Format data into a form the rest of the app expects
cmd
path
data_path