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

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

Overview

Examples:

Update files after changing associations

module_class = FactoryGirl.build(
  :dummy_module_class
)
# factory already wrote template when build returned

# update associations
rank = FactoryGirl.generate :dummy_rank
module_class.rank = rank

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

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_classMetasploit::Model::Module::Class



31
32
33
# File 'app/models/metasploit/model/module/class/spec/template.rb', line 31

def module_class
  @module_class
end

Instance Method Details

#ancestor_templatesArray<Metasploit::Model::Module::Ancestor::Spec::Template>, []

Template for #module_class Metasploit::Model::Module::Class#ancestors with the addition of #module_class to the Spec::Template#locals and adding 'module/classes' to the front of the Spec::Template#search_pathnames.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/metasploit/model/module/class/spec/template.rb', line 51

def ancestor_templates
  unless instance_variable_defined? :@ancestor_templates
    if module_class
      @ancestor_templates = module_class.ancestors.collect { |module_ancestor|
        Metasploit::Model::Module::Ancestor::Spec::Template.new(
            module_ancestor: module_ancestor
        ).tap { |module_ancestor_template|
          module_ancestor_template.locals[:module_class] = module_class
          module_ancestor_template.overwrite = true

          module_ancestor_template.search_pathnames.unshift(
              Pathname.new('module/classes')
          )
        }
      }
    end

    @ancestor_templates ||= []
  end

  @ancestor_templates
end

#ancestor_templates_validvoid (private)

This method returns an undefined value.

Validates that all #ancestor_templates are valid.



87
88
89
90
91
92
93
94
95
# File 'app/models/metasploit/model/module/class/spec/template.rb', line 87

def ancestor_templates_valid
  # can't use ancestor_templates.all?(&:valid?) as it will short-circuit and want all ancestor_templates to have
  # validation errors
  valids = ancestor_templates.map(&:valid?)

  unless valids.all?
    errors.add(:ancestor_templates, :invalid, value: ancestor_templates)
  end
end

#writevoid

This method returns an undefined value.

Writes #ancestor_templates to disk.



78
79
80
# File 'app/models/metasploit/model/module/class/spec/template.rb', line 78

def write
  ancestor_templates.each(&:write)
end