Class: Metasploit::Credential::Search::Operator::Type

Inherits:
Model::Search::Operator::Attribute
  • Object
show all
Defined in:
app/models/metasploit/credential/search/operator/type.rb

Overview

Operator that searches a polymorphic ‘#type` attribute. Search terms are restricted to set of `Class#name`s and `Class#model_name.human` with the `Class#model_name.human` being translated to `Class#name` in the operation returned by #operate_on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#class_namesArray<String>

The name of the classes that are allowed for #attribute. ‘Class.name`s must be supplied as there’s no way in Rails to reflectively determine all allowed values for a polymorphic type.

Returns:

  • (Array<String>)


14
# File 'app/models/metasploit/credential/search/operator/type.rb', line 14

attr_writer :class_names

Instance Method Details

#attributeSymbol

Defaults to ‘:type` as all STI tables in `ActiveRecord::Base` use `type` as teh type attribute by default. Override to search foreign key types, which are prefixed with the association name.

Returns:

  • (Symbol)


31
32
33
# File 'app/models/metasploit/credential/search/operator/type.rb', line 31

def attribute
  @attribute ||= :type
end

#class_name_by_class_model_name_humanHash{String => String}

Maps ‘Class.model_name.human` to `Class.name` for all #classes.

Returns:

  • (Hash{String => String})

    Maps ‘Class.model_name.name`s to `Class.name`s so `Class.model_names.name` can be converted to `Class.name` for the in database search.



47
48
49
50
51
# File 'app/models/metasploit/credential/search/operator/type.rb', line 47

def class_name_by_class_model_name_human
  @class_name_by_class_model_name_human ||= class_set.each_with_object({}) { |klass, class_name_by_class_model_name_human|
    class_name_by_class_model_name_human[klass.model_name.human] = klass.name
  }
end

#class_setSet<Class>

Set of ‘Class`es whose `Class#name` or `Class.model_name.name`

Returns:

  • (Set<Class>)


56
57
58
59
60
# File 'app/models/metasploit/credential/search/operator/type.rb', line 56

def class_set
  @class_set ||= class_names.each_with_object(Set.new) { |class_name, set|
    set.add class_name.constantize
  }
end

#operation_class_nameString

Returns ‘Metasploit::Credential::Search::Operation::Type’.

Returns:

  • (String)

    ‘Metasploit::Credential::Search::Operation::Type’



63
64
65
# File 'app/models/metasploit/credential/search/operator/type.rb', line 63

def operation_class_name
  'Metasploit::Credential::Search::Operation::Type'
end

#typeString

The type attribute for STI and polymorphic associations is a string on the database.

Returns:

  • (String)

    ‘:string`



70
71
72
# File 'app/models/metasploit/credential/search/operator/type.rb', line 70

def type
  :string
end