Sha256: 9734a49370e5c46e7a1630dbcec5dd0c8d4f6335a137e60882eeaefcdb0c83bc

Contents?: true

Size: 1.73 KB

Versions: 15

Compression:

Stored size: 1.73 KB

Contents

module Metasploit
  module Model
    module Search
      # Generalizes operators from attributes to anything directly registered as an operator on a class.
      module With
        extend ActiveSupport::Concern

        # Defines `search_with` DSL, which is a lower-level way than search_attribute to add operators.  `search_with`
        # allows instance of arbitrary operator_classes to be registered in {#search_with_operator_by_name}.
        module ClassMethods
          # Declares that this class should be search with an instance of the given `operator_class`.
          #
          # @param operator_class [Class<Metasploit::Model::Search::Operator::Base>] a class to initialize.
          # @param options [Hash] Options passed to `operator_class.new` along with `{:klass => self}`, so that the
          #   `operator_class` instance knows it was registered as search this class.
          # @return [Metasploit::Model::Search::Operator::Base]
          # @raise (see Metasploit::Model::Base#invalid!)
          def search_with(operator_class, options={})
            merged_operations = options.merge(
                :klass => self
            )
            operator = operator_class.new(merged_operations)
            operator.valid!

            search_with_operator_by_name[operator.name] = operator
          end

          # Operators registered with {#search_with}.
          #
          # @return [Hash{Symbol => Metasploit::Model::Search::Operator::Base}] Maps
          #   {Metasploit::Model::Search::Operator::Base#name} keys to {Metasploit::Model::Search::Operator::Base#name}
          #   values.
          def search_with_operator_by_name
            @search_with_operator_by_name ||= {}
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
metasploit-model-0.25.7 lib/metasploit/model/search/with.rb
metasploit-model-0.25.7-java lib/metasploit/model/search/with.rb
metasploit-model-0.25.6 lib/metasploit/model/search/with.rb
metasploit-model-0.25.6-java lib/metasploit/model/search/with.rb
metasploit-model-0.25.3 lib/metasploit/model/search/with.rb
metasploit-model-0.25.3-java lib/metasploit/model/search/with.rb
metasploit-model-0.25.2 lib/metasploit/model/search/with.rb
metasploit-model-0.25.2-java lib/metasploit/model/search/with.rb
metasploit-model-0.25.1 lib/metasploit/model/search/with.rb
metasploit-model-0.25.1-java lib/metasploit/model/search/with.rb
metasploit-model-0.25.1.pre.metasploit.pre.model.pre.search.pre.operator.pre.and.pre.operation.pre.groups-java lib/metasploit/model/search/with.rb
metasploit-model-0.25.1.pre.metasploit.pre.model.pre.search.pre.operator.pre.and.pre.operation.pre.groups lib/metasploit/model/search/with.rb
metasploit-model-0.24.1-java lib/metasploit/model/search/with.rb
metasploit-model-0.24.1 lib/metasploit/model/search/with.rb
metasploit-model-0.24.1.pre.semantic.pre.versioning.pre.2.pre.0 lib/metasploit/model/search/with.rb