Module: Metasploit::Model::Search::With::ClassMethods

Defined in:
lib/metasploit/model/search/with.rb

Overview

Defines search_with DSL, which is a lower-level way than search_attribute to add operators. search_with allows instance of arbitrary operator_classes to be registered in #search_with_operator_by_name.

Instance Method Summary collapse

Instance Method Details

#search_with(operator_class, options = {}) ⇒ Metasploit::Model::Search::Operator::Base

Declares that this class should be search with an instance of the given operator_class.

Parameters:

  • operator_class (Class<Metasploit::Model::Search::Operator::Base>)

    a class to initialize.

  • options (Hash) (defaults to: {})

    Options passed to operator_class.new along with {:klass => self}, so that the operator_class instance knows it was registered as search this class.

Returns:



58
59
60
61
62
63
64
65
66
# File 'lib/metasploit/model/search/with.rb', line 58

def search_with(operator_class, options={})
  merged_operations = options.merge(
      :klass => self
  )
  operator = operator_class.new(merged_operations)
  operator.valid!

  search_with_operator_by_name[operator.name] = operator
end

#search_with_operator_by_nameHash{Symbol => Metasploit::Model::Search::Operator::Base}

Operators registered with #search_with.

Returns:



73
74
75
# File 'lib/metasploit/model/search/with.rb', line 73

def search_with_operator_by_name
  @search_with_operator_by_name ||= {}
end