Sha256: 7143d5de622ad1b64400396baf7cf86218bfa2055547c7a443c8a752a82ba4a7

Contents?: true

Size: 1.87 KB

Versions: 15

Compression:

Stored size: 1.87 KB

Contents

module Metasploit
  module Model
    module Search
      module Operator
        # Methods to lookup help text for an operator with a given `#name` registered to a given `#klass`.
        module Help
          # @note This uses I18n.translate along with {Metasploit::Model::Translation#search_i18n_scope},
          #   the value is not cached to support changing the I18n.locale and getting the correct help message for that
          #   locale.
          #
          # The help for this operator.
          #
          # @see https://github.com/rails/rails/blob/6c2810b8ed692004dca43e554982cdfdb8517b80/activemodel/lib/active_model/errors.rb#L408-L435
          def help
            defaults = []
            klass_i18n_scope = klass.i18n_scope

            klass.lookup_ancestors.each do |ancestor|
              # a specific operator for a given Class#ancestors member
              defaults << :"#{klass_i18n_scope}.ancestors.#{ancestor.model_name.i18n_key}.search.operator.names.#{name}.help"
            end

            operator_class = self.class
            operator_i18n_scope = operator_class.i18n_scope

            operator_class.lookup_ancestors.each do |ancestor|
              # a specific name for a given operator
              defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.names.#{name}.help"
              # a specific operator class
              defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.help"
            end

            # use first default as key because it is most specific default, that is closest to klass.
            key = defaults.shift
            options = {
                default: defaults,
                model: klass.model_name.human,
                name: name
            }

            ::I18n.translate(key, options)
          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/operator/help.rb
metasploit-model-0.25.7-java lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.6 lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.6-java lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.3 lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.3-java lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.2 lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.2-java lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.1 lib/metasploit/model/search/operator/help.rb
metasploit-model-0.25.1-java lib/metasploit/model/search/operator/help.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/operator/help.rb
metasploit-model-0.25.1.pre.metasploit.pre.model.pre.search.pre.operator.pre.and.pre.operation.pre.groups lib/metasploit/model/search/operator/help.rb
metasploit-model-0.24.1-java lib/metasploit/model/search/operator/help.rb
metasploit-model-0.24.1 lib/metasploit/model/search/operator/help.rb
metasploit-model-0.24.1.pre.semantic.pre.versioning.pre.2.pre.0 lib/metasploit/model/search/operator/help.rb