Module: MetasploitDataModels::Match::Parent::ClassMethods

Defined in:
lib/metasploit_data_models/match/parent.rb

Overview

Examples:

Declaring children classes

class FirstChild < Metasploit::Model::Base
  extend MetasploitDataModels::Match::Child

  #
  # CONSTANTS
  #

  # Matches a range.
  MATCH_REGEXP = /\A\d+-\d+\z/

  #
  # Attributes
  #

  # @!attribute value
  #   The range
  #
  attr_accessor :value
end

class SecondChild < Metasploit::Model::Base
  extend MetasploitDataModels::Match::Child

  #
  # CONSTANTS
  #

  # Matches a range.
  MATCH_REGEXP = /\A\d+\z/

  #
  # Attributes
  #

  # @!attribute value
  #   The range
  #
  attr_accessor :value
end

class Parent
  include MetasploitDataModels::Match::Parent

  match_children_named %w{FirstChild SecondChild}
end

Instance Method Summary collapse

Instance Method Details

#match_child_namesArray<String>

Class#name for classes that extend Child and should be tested using match.

Returns:

  • (Array<String>)

62
63
64
# File 'lib/metasploit_data_models/match/parent.rb', line 62

def match_child_names
  @match_child_names ||= []
end

#match_childrenArray<String>

Classes on which to call match in MetasploitDataModels::Match::Parent#match_child

Returns:

  • (Array<String>)

69
70
71
# File 'lib/metasploit_data_models/match/parent.rb', line 69

def match_children
  @match_children ||= match_child_names.map(&:constantize)
end

#match_children_named(class_names) ⇒ Array<String>

Note:

Classes named class_names

Register the given class_names as Class#names for children classes for MetasploitDataModels::Match::Parent#match_child.

Returns:

  • (Array<String>)

    class_names`


78
79
80
# File 'lib/metasploit_data_models/match/parent.rb', line 78

def match_children_named(class_names)
  @match_child_names = class_names
end