Module: Dradis::Plugins::Import::Filters

Defined in:
lib/dradis/plugins/import/filters.rb,
lib/dradis/plugins/import/filters/base.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Class Method Details

.[](plugin) ⇒ Object

Provides access to filters by plugin :api: public



38
39
40
# File 'lib/dradis/plugins/import/filters.rb', line 38

def [](plugin)
  _filters[plugin]
end

._filtersObject

:api: private



43
44
45
# File 'lib/dradis/plugins/import/filters.rb', line 43

def _filters
  @filters ||= {}
end

.add(plugin, label, filter, &block) ⇒ Object

– 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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dradis/plugins/import/filters.rb', line 19

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