Sha256: 4717ac3df8dae8589d2ef6ca28cf58418fc5ee9b3887a114c6ab3a64ea44e685

Contents?: true

Size: 1.42 KB

Versions: 54

Compression:

Stored size: 1.42 KB

Contents

require 'util/miq-xml'

class ScanProfilesBase
  def self.get_class(type, from)
    k = from.instance_variable_get("@scan_#{type}_class")
    return k unless k.nil?

    k = "#{from.name.underscore.split('_')[0..-2].join('_').camelize}#{type.camelize}"
    require "metadata/ScanProfile/#{k}"
    from.instance_variable_set("@scan_#{type}_class", Object.const_get(k))
  end

  def self.scan_item_class;     get_class('item',    self); end

  def self.scan_profile_class;  get_class('profile', self); end

  def self.scan_profiles_class; self; end

  include Enumerable

  attr_accessor :profiles

  def initialize(dataHash, options = {})
    @params = dataHash
    @options = options
    @xml_class = @options[:xml_class] || XmlHash::Document
    @profiles = @params.nil? ? [] : @params.collect { |p| self.class.scan_profile_class.new(p, @options) }
  end

  def each
    profiles.each { |p| yield p }
  end

  def each_scan_definition(type = nil, &blk)
    profiles.each { |p| p.each_scan_definition(type, &blk) }
  end

  def each_scan_item(type = nil, &blk)
    profiles.each { |p| p.each_scan_item(type, &blk) }
  end

  def parse_data(obj, data, &blk)
    each_scan_item { |si| si.parse_data(obj, data, &blk) }
  end

  def to_xml
    xml = @xml_class.createDoc("<scan_profiles/>")
    each { |p| xml.root << p.to_xml }
    xml
  end

  def to_hash
    {:scan_profiles => collect(&:to_hash)}
  end

  def to_yaml
    YAML.dump(to_hash)
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
manageiq-smartstate-0.8.1 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.8.0 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.7.0 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.6.2 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.10 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.3.10 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.6.1 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.3.9 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.6.0 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.9 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.8 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.3.8 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.7 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.3.7 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.6 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.3.6 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.5 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.4 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.3.5 lib/metadata/ScanProfile/ScanProfilesBase.rb
manageiq-smartstate-0.5.3 lib/metadata/ScanProfile/ScanProfilesBase.rb