Class: Metasploit::Model::Search::Operator::Group::Base

Inherits:
Delegation show all
Defined in:
app/models/metasploit/model/search/operator/group/base.rb

Overview

Operator that produces group operations.

Direct Known Subclasses

Intersection, Union

Instance Attribute Summary

Attributes inherited from Base

#klass

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Delegation

#name, #operator, operator_name

Methods inherited from Base

#name

Methods included from Help

#help

Methods inherited from Base

#initialize, #valid!

Constructor Details

This class inherits a constructor from Metasploit::Model::Base

Class Method Details

.operation_classClass<Metasploit::Model::Search::Operation::Group::Base>

Group operation class to wrap #children in and return from #operate_on.



27
28
29
# File 'app/models/metasploit/model/search/operator/group/base.rb', line 27

def self.operation_class
  @operation_class ||= operation_class_name.constantize
end

.operation_class_nameString

The name of the operation_class.

Returns:

  • (String)


17
# File 'app/models/metasploit/model/search/operator/group/base.rb', line 17

class_attribute :operation_class_name

.operation_class_name!void

This method returns an undefined value.

Sets the operation_class_name to the operation with same name as this operator, but with 'Operation' substituted for 'Operator'.



35
36
37
# File 'app/models/metasploit/model/search/operator/group/base.rb', line 35

def self.operation_class_name!
  self.operation_class_name = name.gsub('Operator', 'Operation')
end

.operation_class_name=(operation_class_name) ⇒ void

This method returns an undefined value.

Set the name of the operation_class.

Parameters:

  • operation_class_name (String)


17
# File 'app/models/metasploit/model/search/operator/group/base.rb', line 17

class_attribute :operation_class_name

Instance Method Details

#children(formatted_value) ⇒ Array<Metasploit::Model::Search::Operation::Base>

Parameters:

  • formatted_value (String)

    value parsed from formatted operation

Returns:

Raises:

  • (NotImplementedError)


49
50
51
# File 'app/models/metasploit/model/search/operator/group/base.rb', line 49

def children(formatted_value)
  raise NotImplementedError
end

#operate_on(formatted_value) ⇒ Metasploit::Model::Search::Operation::Group::Base

Group's children operating on formatted_value.

Parameters:

  • formatted_value (String)

    value parsed from formatted operation.

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/metasploit/model/search/operator/group/base.rb', line 63

def operate_on(formatted_value)
  children = self.children(formatted_value)

  # filter children for validity as valid values for one child won't necessarily be valid values for another child.
  # this is specifically a problem with Metasploit::Model::Search::Operation::Set as no partial matching is allowed,
  # but can also be a problem with string vs integer operations.
  valid_children = children.select(&:valid?)

  operation_class.new(
      :children => valid_children,
      :operator => self,
      :value => formatted_value
  )
end

#operation_classClass<Metasploit::Model::Search::Operation::Group::Base>

Group operation class to wrap #children in and return from #operate_on.



54
55
56
# File 'app/models/metasploit/model/search/operator/group/base.rb', line 54

def operation_class
  self.class.operation_class
end