Sha256: 3819e8b31af7480ba1699f464991f41c8d789958dea421f93150f4a0f36aa465

Contents?: true

Size: 1.39 KB

Versions: 42

Compression:

Stored size: 1.39 KB

Contents

# Namespace for search operations.  {parse} acts as a factory to parse a `String` and return a type-specific
# operation.
module Metasploit::Model::Search::Operation
  extend ActiveSupport::Autoload

  autoload :Association
  autoload :Base
  autoload :Boolean
  autoload :Date
  autoload :Group
  autoload :Integer
  autoload :Null
  autoload :Set
  autoload :String
  autoload :Value

  # @param options [Hash{Symbol => Object}]
  # @option options [Metasploit::Module::Search::Query] :query The query that the parsed operation is a part.
  # @option options [String] :formatted_operation A '<operator>:<value>' string.
  # @return [Metasploit::Model::Search::Operation::Base, Array<Metasploit::Model::Search::Operation::Base>]
  #   operation(s) parsed from the formatted operation.
  # @raise [KeyError] unless :formatted_operation is given.
  # @raise [KeyError] unless :query is given.
  def self.parse(options={})
    formatted_operation = options.fetch(:formatted_operation)
    query = options.fetch(:query)

    formatted_operator, formatted_value = formatted_operation.split(':', 2)
    operator = query.parse_operator(formatted_operator)

    # formatted_value will be nil if formatted_operation did not contain a ':', it should be treated the same
    # as nothing after the ':'.
    formatted_value ||= ''
    operation_or_operations = operator.operate_on(formatted_value)

    operation_or_operations
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
metasploit-model-5.0.2 lib/metasploit/model/search/operation.rb
metasploit-model-5.0.1 lib/metasploit/model/search/operation.rb
metasploit-model-5.0.0 lib/metasploit/model/search/operation.rb
metasploit-model-4.0.6 lib/metasploit/model/search/operation.rb
metasploit-model-4.0.5 lib/metasploit/model/search/operation.rb
metasploit-model-4.0.4 lib/metasploit/model/search/operation.rb
metasploit-model-4.0.3 lib/metasploit/model/search/operation.rb
metasploit-model-4.0.2 lib/metasploit/model/search/operation.rb
metasploit-model-4.0.1 lib/metasploit/model/search/operation.rb
metasploit-model-4.0.0 lib/metasploit/model/search/operation.rb
metasploit-model-3.1.4 lib/metasploit/model/search/operation.rb
metasploit-model-3.1.3 lib/metasploit/model/search/operation.rb
metasploit-model-3.1.2 lib/metasploit/model/search/operation.rb
metasploit-model-3.1.1 lib/metasploit/model/search/operation.rb
metasploit-model-3.1.0 lib/metasploit/model/search/operation.rb
metasploit-model-3.0.0 lib/metasploit/model/search/operation.rb
metasploit-model-2.0.4 lib/metasploit/model/search/operation.rb
metasploit-model-2.0.3 lib/metasploit/model/search/operation.rb
metasploit-model-2.0.2 lib/metasploit/model/search/operation.rb
metasploit-model-2.0.1 lib/metasploit/model/search/operation.rb