Sha256: 0e4ece6b63dfb8caf963204a308c52f4d1c568e6b25ab32fd92282e6af9b0d1d

Contents?: true

Size: 1.47 KB

Versions: 18

Compression:

Stored size: 1.47 KB

Contents

# DSL for declaring {Metasploit::Model::Configuration::Child children} of {Metasploit::Model::Configuration}
module Metasploit::Model::Configuration::Parent
  # Declares a {Metasploit::Model::Configuration::Child} with the given `name`.
  #
  # @param name [Symbol] The name of the child.
  # @return [void]
  def child(name)
    child_class_attribute_name = "#{name}_class"
    child_class_instance_variable_name = "@#{child_class_attribute_name}".to_sym
    child_instance_variable_name = "@#{name}".to_sym

    #
    # Attributes
    #

    # @!attribute [rw] <name>_class
    #   The `Class` used to create {#<name>}.
    #
    #   @return [Class]
    attr_writer child_class_attribute_name

    #
    # Methods
    #

    define_method(name) do
      unless instance_variable_defined? child_instance_variable_name
        child_instance = send(child_class_attribute_name).new
        child_instance.configuration = self

        instance_variable_set child_instance_variable_name, child_instance
      end

      instance_variable_get child_instance_variable_name
    end

    define_method(child_class_attribute_name) do
      child_class = instance_variable_get child_class_instance_variable_name

      unless child_class
        require "metasploit/model/configuration/#{name}"

        child_class = "Metasploit::Model::Configuration::#{name.to_s.camelize}".constantize
        instance_variable_set child_class_instance_variable_name, child_class
      end

      child_class
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
metasploit-model-0.27.0.pre.dep.pre.railties lib/metasploit/model/configuration/parent.rb
metasploit-model-0.26.1-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.26.1 lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.7 lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.7-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.6 lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.6-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.3 lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.3-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.2 lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.2-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.1 lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.1-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.1.pre.metasploit.pre.model.pre.search.pre.operator.pre.and.pre.operation.pre.groups-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.25.1.pre.metasploit.pre.model.pre.search.pre.operator.pre.and.pre.operation.pre.groups lib/metasploit/model/configuration/parent.rb
metasploit-model-0.24.1-java lib/metasploit/model/configuration/parent.rb
metasploit-model-0.24.1 lib/metasploit/model/configuration/parent.rb
metasploit-model-0.24.1.pre.semantic.pre.versioning.pre.2.pre.0 lib/metasploit/model/configuration/parent.rb