Class: Metasploit::Model::Search::Operator::Single
- Defined in:
- app/models/metasploit/model/search/operator/single.rb
Overview
If all you want do is customize the name and operation Class
that your custom operator class returns from
#operate_on
, then you can subclass Single instead of
Base.
class MyOperator < Metasploit::Model::Search::Operator::Single
# Name of this operator. The name of the operator is matched to the string before the ':' in a formatted
# operation.
#
# @return [Symbol]
def name
# ...
end
# `Class.name` of `Class` returned from {Metasploit::Model::Search::Operator::Single#operate_on}.
#
# @return [String] a `Class.name`
def operation_class_name
# ...
end
end
Constant Summary collapse
- MODULE_SEPARATOR =
Separator between parent and child module/class names.
'::'
- OPERATION_NAMESPACE_NAME =
Name of namespace module for operations returned from #operation_class and used by #operate_on.
"Metasploit::Model::Search::Operation"
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.constant_name(type) ⇒ String
The constant name for the given type.
Instance Method Summary collapse
- #operate_on(formatted_value) ⇒ Metasploit::Model::Search::Operation::Base
-
#operation_class ⇒ Class<Metasploit::Model::Search::Operation::Base>
protected
The #type-specific Metasploit::Model::Search::Operation::Base subclass.
-
#operation_class_name ⇒ String
protected
The name of the #type-specific Metasploit::Model::Search::Operation::Base subclass.
-
#type ⇒ Symbol
abstract
Type of the attribute.
Methods inherited from Base
Methods included from Help
Methods inherited from Base
Constructor Details
This class inherits a constructor from Metasploit::Model::Base
Class Method Details
.constant_name(type) ⇒ String
The constant name for the given type.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/metasploit/model/search/operator/single.rb', line 42 def self.constant_name(type) case type when Hash if type.length < 1 raise ArgumentError, "Cannot destructure a Hash without entries" end if type.length > 1 raise ArgumentError, "Cannot destructure a Hash with multiple entries" end partial_types = type.first partial_constant_names = partial_types.collect { |partial_type| constant_name(partial_type) } partial_constant_names.join(MODULE_SEPARATOR) when Symbol type.to_s.camelize else raise ArgumentError, "Can only convert Hashes and Symbols to constant names, not #{type.inspect}" end end |
Instance Method Details
#operate_on(formatted_value) ⇒ Metasploit::Model::Search::Operation::Base
71 72 73 74 75 76 |
# File 'app/models/metasploit/model/search/operator/single.rb', line 71 def operate_on(formatted_value) operation_class.new( :value => formatted_value, :operator => self ) end |
#operation_class ⇒ Class<Metasploit::Model::Search::Operation::Base> (protected)
The #type-specific Metasploit::Model::Search::Operation::Base subclass.
94 95 96 97 98 99 100 |
# File 'app/models/metasploit/model/search/operator/single.rb', line 94 def operation_class unless instance_variable_defined? :@operation_class @operation_class = operation_class_name.constantize end @operation_class end |
#operation_class_name ⇒ String (protected)
The name of the #type-specific Metasploit::Model::Search::Operation::Base subclass.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/metasploit/model/search/operator/single.rb', line 106 def operation_class_name unless instance_variable_defined? :@operation_class_name unless type raise ArgumentError, "#{self.class}##{__method__} cannot be derived for #{name} operator because its type is nil" end partial_constant_names = [OPERATION_NAMESPACE_NAME] partial_constant_names << self.class.constant_name(type) @operation_class_name = partial_constant_names.join(MODULE_SEPARATOR) end @operation_class_name end |
#type ⇒ Symbol
subclass and derive operator type.
Type of the attribute.
84 85 86 |
# File 'app/models/metasploit/model/search/operator/single.rb', line 84 def type raise NotImplementedError end |