Module: Metasploit::Model::Derivation::ClassMethods

Defined in:
lib/metasploit/model/derivation.rb

Overview

Defines class methods include #derives, which can be used to declare derived attributes after mixing in Metasploit::Model::Derivation.

Instance Method Summary collapse

Instance Method Details

#derives(attribute, options = {}) ⇒ void

This method returns an undefined value.

Declares that the attribute should be derived using the derived_ method if it is nil before validation.

Parameters:

  • attribute (Symbol)

    the name of the attribute.

  • options (Hash{Symbol => Boolean}) (defaults to: {})

Options Hash (options):

  • :validate (Boolean) — default: false

    If true, validates attribute using DerivationValidator. If false, does no validation on attribute.



72
73
74
75
76
77
78
79
80
81
# File 'lib/metasploit/model/derivation.rb', line 72

def derives(attribute, options={})
  options.assert_valid_keys(:validate)

  validate = options.fetch(:validate, false)
  validate_by_derived_attribute[attribute] = validate

  if validate
    validates attribute, :derivation => true
  end
end

#validate_by_derived_attributeHash{Symbol => Boolean}

Maps a derived attribute (declared with #derives) to whether the attribute should validate as a derivation.

Returns:

  • (Hash{Symbol => Boolean})


86
87
88
# File 'lib/metasploit/model/derivation.rb', line 86

def validate_by_derived_attribute
  @validate_by_derived_attribute ||= {}
end