Sha256: e6e4cb3df1a64973aa9a3b276198ea9e0b2d65e6e635faea64865a5c8829b589

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

require 'metasploit/model/search/operation'

# Operation on an attribute that has a constrained Set of valid
# {Metasploit::Model::Search::Operation::Base#value values}.
class Metasploit::Model::Search::Operation::Set < Metasploit::Model::Search::Operation::Base
  #
  # Validations
  #

  validate :membership

  private

  # Validates that {#value} is a member of {Metasploit::Model::Search::Operation::Base#operator}
  # {Metasploit::Model::Search::Operator::Attribute#attribute_set}.
  #
  # @return [void]
  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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
metasploit-model-0.27.3 app/models/metasploit/model/search/operation/set.rb
metasploit-model-0.27.3-java app/models/metasploit/model/search/operation/set.rb
metasploit-model-0.27.2 app/models/metasploit/model/search/operation/set.rb
metasploit-model-0.27.2-java app/models/metasploit/model/search/operation/set.rb
metasploit-model-0.27.1 app/models/metasploit/model/search/operation/set.rb
metasploit-model-0.27.1-java app/models/metasploit/model/search/operation/set.rb
metasploit-model-0.27.0 app/models/metasploit/model/search/operation/set.rb
metasploit-model-0.27.0-java app/models/metasploit/model/search/operation/set.rb