Class: Metasploit::Model::Search::Operator::Single Abstract

Inherits:
Base
  • Object
show all
Defined in:
app/models/metasploit/model/search/operator/single.rb

Overview

This class is abstract.

Operator that only returns a single operation from #operate_on.

Direct Known Subclasses

Association, Attribute, Null

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

#klass

Class Method Summary collapse

Instance Method Summary collapse

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

.constant_name(type) ⇒ String

The constant name for the given type.

Parameters:

  • type (Symbol, Hash)

Returns:

  • (String)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/metasploit/model/search/operator/single.rb', line 20

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

Creates an operation of the correct type for this operator's #type.

Parameters:

Returns:



49
50
51
52
53
54
# File 'app/models/metasploit/model/search/operator/single.rb', line 49

def operate_on(formatted_value)
  operation_class.new(
      :value => formatted_value,
      :operator => self
  )
end

#operation_classClass<Metasploit::Model::Search::Operation::Base> (protected)

Returns:

Raises:

  • (ArgumentError)


72
73
74
75
76
77
78
# File 'app/models/metasploit/model/search/operator/single.rb', line 72

def operation_class
  unless instance_variable_defined? :@operation_class
    @operation_class = operation_class_name.constantize
  end

  @operation_class
end

#operation_class_nameString (protected)

The name of the #type-specific Metasploit::Model::Search::Operation::Base subclass.

Returns:

  • (String)

Raises:

  • (ArgumentError)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/metasploit/model/search/operator/single.rb', line 84

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

#typeSymbol

This method is abstract.

subclass and derive operator type.

Type of the attribute.

Returns:

  • (Symbol)

Raises:

  • (NotImplementedError)


62
63
64
# File 'app/models/metasploit/model/search/operator/single.rb', line 62

def type
  raise NotImplementedError
end