Class: Metasploit::Model::Module::Instance::Spec::Template

Inherits:
Base
  • Object
show all
Extended by:
Spec::Template::Write
Defined in:
app/models/metasploit/model/module/instance/spec/template.rb

Overview

Writes templates for the #module_instance's #module_class's Class#ancestors to disk.

Examples:

Update files after changing associations

module_instance = FactoryGirl.build(
  :dummy_module_instance,
  module_architectures_length: 0
)
# factory already wrote template when build returned

# update associations
architecture = FactoryGirl.generate :dummy_architecture
module_instance.module_architectures = FactoryGirl.build_list(
  :dummy_module_architecture,
  1,
  architecture: architecture
)

# Now the template on disk is different than the module_instance, so regenerate the template
Metasploit::Model::Module::Instance::Spec::Template.write(module_instance: module_instance)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Spec::Template::Write

write!

Methods inherited from Base

#initialize, #valid!

Constructor Details

This class inherits a constructor from Metasploit::Model::Base

Instance Attribute Details

#module_instanceMetasploit::Model::Module::Instance



38
39
40
# File 'app/models/metasploit/model/module/instance/spec/template.rb', line 38

def module_instance
  @module_instance
end

Instance Method Details

#class_templateMetasploit::Model::Module::Class::Spec::Template?

Template for #module_instance Metasploit::Model::Module::Instance#module_class with the addition of #module_instance to the Spec::Template#locals and adding 'module/instances' to the front of the Spec::Template#search_pathnames.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/metasploit/model/module/instance/spec/template.rb', line 60

def class_template
  unless instance_variable_defined? :@class_template
    if module_instance
      class_template = Metasploit::Model::Module::Class::Spec::Template.new(
          module_class: module_instance.module_class
      )
      class_template.ancestor_templates.each do |ancestor_template|
        ancestor_template.locals[:module_instance] = module_instance

        ancestor_template.search_pathnames.unshift(
            Pathname.new('module/instances')
        )
      end

      @class_template = class_template
    else
      @class_template = nil
    end
  end

  @class_template
end

#class_template_validvoid (private)

This method returns an undefined value.

Validates that #class_template is valid when present.



96
97
98
99
100
# File 'app/models/metasploit/model/module/instance/spec/template.rb', line 96

def class_template_valid
  if class_template && !class_template.valid?
    errors.add(:class_template, :invalid, value: class_template)
  end
end

#writevoid

This method returns an undefined value.

Writes #class_template to disk.



88
89
# File 'app/models/metasploit/model/module/instance/spec/template.rb', line 88

delegate :write,
to: :class_template