Sha256: 5fa4989de76329857da724a15d0e3e5f838cdb977b1e70580db13ba3e72c08e1

Contents?: true

Size: 1.44 KB

Versions: 32

Compression:

Stored size: 1.44 KB

Contents

module Dradis
  module Plugins
    module Import

      module Filters
        class << self
          # -- Class Methods --------------------------------------------------------
          # One Import plugin can define several filters (e.g. to query different
          # endpoints of a remote API).
          #
          # Use this method in your Importer to register different filters, pass a
          # block or a class.
          #
          # Examples:
          #
          # register_filter :by_osvdb_id do
          #   def c
          # end
          def add(plugin, label, filter, &block)
            filter ||= Class.new(Dradis::Plugins::Import::Filters::Base)
            filter.class_eval(&block) if block_given?

            unless filter.method_defined?(:query)
              raise NoMethodError, "query() is not declared in the #{label.inspect} filter"
            end

            base = Dradis::Plugins::Import::Filters::Base
            unless filter.ancestors.include?(base)
              raise "#{label.inspect} is not a #{base}"
            end

            _filters[plugin]        = {} unless _filters.key?(plugin)
            _filters[plugin][label] = filter
          end

          # Provides access to filters by plugin
          # :api: public
          def [](plugin)
            _filters[plugin]
          end

          # :api: private
          def _filters
            @filters ||= {}
          end
        end
      end

    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
dradis-plugins-4.14.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.13.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.11.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.10.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.9.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.8.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.7.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.6.1 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.5.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.4.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.3.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.2.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.1.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-4.0.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-3.22.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-3.21.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-3.20.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-3.19.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-3.18.0 lib/dradis/plugins/import/filters.rb
dradis-plugins-3.17.0 lib/dradis/plugins/import/filters.rb