Sha256: 5101763056d3a4877a373ee6813fe587aee05e9a0c03c1140eb60e7d86922983

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require 'soar_auditing_provider/nfr_match_error'

module SoarAuditingProvider
  class AuditingProviderAPI
    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 = nil)
      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]
      clazz = (auditor_selected.class == Class) ? auditor_selected.to_s : auditor_selected
      @auditor = Object::const_get(clazz).new
      configure_auditor(@auditor, configuration)
      @auditor
    end

    protected
    
    def configure_auditor(auditor, configuration = nil)
      raise NotImplementedError.new("You should override this method and configure your auditor")
    end    

    private


  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soar_auditing_provider-0.5.0 lib/soar_auditing_provider/auditing_provider_api.rb