Sha256: abec18f51ec64aec3632e05ba1cb807fb17dec9a354066c749a6da2f3c245bdf

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

module SoarAuditingProvider
  class AuditingProviderAPI
    DEFAULT = {} unless defined? DEFAULT; DEFAULT.freeze

    attr_accessor :auditors
    attr_accessor :auditor

    def initialize(auditors)
      raise ArgumentError.new("Invalid auditors provided") if not auditors.is_a?(Hash)
      raise ArgumentError.new("No auditors provided") if auditors.nil? or auditors.empty?
      @auditors = auditors
    end

    def debug(data)
      @auditor.debug(data)
    end

    def <<(data)
      @auditor.info(data)
    end

    def info(data)
      @auditor.info(data)
    end

    def error(data)
      @auditor.error(data)
    end

    def warn(data)
      @auditor.warn(data)
    end

    def fatal(data)
      @auditor.fatal(data)
    end

    def select(nfrs = DEFAULT)
      if nfrs.nil? or nfrs.empty?
        auditor_selected = auditors.keys.first
      else
        auditor_selected = nil
        auditors.each do |auditor, configuration|
          auditor_nfrs = configuration['nfrs']
          nfrs_matched = true
          nfrs.each do |nfr, value|
            nfrs_matched = false if not auditor_nfrs[nfr] or (auditor_nfrs[nfr] != value)
          end
          if nfrs_matched
            auditor_selected = auditor
            break
          end
        end
        raise NFRMatchError.new("Could not match NFRs to an auditor") if auditor_selected.nil?
      end
      configuration = auditors[auditor_selected]
      @auditor = auditor_selected
      return @auditor, configuration
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
soar_auditing_provider_api-0.8.0 lib/soar_auditing_provider_api/auditing_provider_api.rb
soar_auditing_provider-0.7.0 lib/soar_auditing_provider/auditing_provider_api.rb