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 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