Class: Metasploit::Model::Search::Operation::Set

Inherits:
Base
  • Object
show all
Extended by:
ActiveSupport::Autoload
Defined in:
app/models/metasploit/model/search/operation/set.rb

Overview

Operation on an attribute that has a constrained Set of valid values.

Direct Known Subclasses

Integer, String

Defined Under Namespace

Classes: Integer, String

Instance Attribute Summary

Attributes inherited from Base

#operator, #value

Instance Method Summary collapse

Methods inherited from Base

#operator_valid

Methods inherited from Base

#initialize, #valid!

Constructor Details

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

Instance Method Details

#membershipvoid (private)

This method returns an undefined value.

Validates that Base#value is a member of Base#operator Metasploit::Model::Search::Operator::Attribute#attribute_set.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/metasploit/model/search/operation/set.rb', line 21

def membership
  if operator
    attribute_set = operator.attribute_set

    unless attribute_set.include? value
      # sort (because Sets are unordered) before inspecting so that lexigraphical sorting is NOT used
      sorted = attribute_set.sort
      # use inspect to differentiate between strings and integers or string and symbols
      inspected = sorted.map(&:inspect)

      # format as a human readable Set using { }
      comma_separated = inspected.join(', ')
      human_set = "{#{comma_separated}}"

      errors.add(:value, :inclusion, set: human_set)
    end
  end
end