Sha256: 5873474f673a9ba4a46978d639c17bfbb2304a020bc89ffcc2911b7f64b61c85

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 KB

Contents

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

        autoload :Group

        # @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
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
metasploit-model-0.27.3 lib/metasploit/model/search/operation.rb
metasploit-model-0.27.3-java lib/metasploit/model/search/operation.rb
metasploit-model-0.27.2 lib/metasploit/model/search/operation.rb
metasploit-model-0.27.2-java lib/metasploit/model/search/operation.rb
metasploit-model-0.27.1 lib/metasploit/model/search/operation.rb
metasploit-model-0.27.1-java lib/metasploit/model/search/operation.rb
metasploit-model-0.27.0 lib/metasploit/model/search/operation.rb
metasploit-model-0.27.0-java lib/metasploit/model/search/operation.rb