Sha256: b7fa42c37bee82884e1b03194801a553b632ebae7caad8d23bd77b53728d6e7d

Contents?: true

Size: 1.27 KB

Versions: 122

Compression:

Stored size: 1.27 KB

Contents

# Operation on an attribute that is a polymorphic type containing a `Class#name`.
class Metasploit::Credential::Search::Operation::Type < Metasploit::Model::Search::Operation::Base
  include ActiveModel::Validations::Callbacks

  #
  # Callbacks
  #

  before_validation :convert_value_to_class_name

  #
  # Validations
  #

  validate :class_name

  #
  # Instance Methods
  #

  private

  # Validates that {#formatted_value} either is a `Class.name` or is a `Class.model_name.human` that can be converted to
  # a `Class.name`.
  def class_name
    if operator && !operator.class_names.include?(value)
      human_class_name_conversions = operator.class_name_by_class_model_name_human.collect { |class_model_name_human, class_name|
        "#{class_model_name_human.inspect} => #{class_name.inspect}"
      }
      human_class_name_conversion = "{#{human_class_name_conversions.join(', ')}}"

      errors.add(
          :value,
          :class_name_conversion,
          class_name_conversion: human_class_name_conversion
      )
    end
  end

  # Converts the formatted value to a class name
  def convert_value_to_class_name
    if operator
      class_name = operator.class_name_by_class_model_name_human[@value]

      if class_name
        @value = class_name
      end
    end
  end
end

Version data entries

122 entries across 122 versions & 1 rubygems

Version Path
metasploit-credential-6.0.11 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.10 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.9 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.8 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.7 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.6 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.5 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.4 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.3 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.2 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.1 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-6.0.0 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.9 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.8 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.7 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.6 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.5 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.4 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.3 app/models/metasploit/credential/search/operation/type.rb
metasploit-credential-5.0.2 app/models/metasploit/credential/search/operation/type.rb