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

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

Overview

Writes templates for the #module_ancestor to disk.

Examples:

Update files after changing

module_ancestor = FactoryGirl.build(
  :dummy_module_ancestor
)
# factory already wrote template when build returned

# update
module_ancestor.module_type = FactoryGirl.generate :metasploit_model_module_type

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

Constant Summary collapse

DEFAULT_SEARCH_PATHNAMES =

Default value for #search_pathnames.

[
    Pathname.new('module/ancestors')
]
DEFAULT_SOURCE_RELATIVE_NAME =

Default value for #source_relative_name.

'base'

Constants inherited from Spec::Template

Spec::Template::BACKTRACE_FILE_REGEXP, Spec::Template::EXPLICIT_TRIM_MODE, Spec::Template::EXTENSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Spec::Template::Write

write, write!

Methods inherited from Spec::Template

#find_pathname, #partial_pathname, #render, #render_super, #result, root, root=, #search_real_pathnames, #source_pathname, #write

Methods inherited from Base

#initialize, #valid!

Constructor Details

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

Instance Attribute Details

#metasploit_module_relative_nameString

Name of the Class/Module declared in the template file.

Returns:

  • (String)


37
# File 'app/models/metasploit/model/module/ancestor/spec/template.rb', line 37

attr_writer :metasploit_module_relative_name

#module_ancestorMetasploit::Model::Module::Ancestor

The module ancestor to write.



43
44
45
# File 'app/models/metasploit/model/module/ancestor/spec/template.rb', line 43

def module_ancestor
  @module_ancestor
end

Instance Method Details

#destination_pathnamePathname?

The pathname where to Spec::Template::Write#write to template results.

Returns:

  • (Pathname)

    `Metasploit::Model::Module::Ancestor#real_pathname.

  • (nil)

    if #module_ancestor is nil.

  • (nil)

    if #module_ancestor's Metasploit::Model::Module::Ancestor#real_pathname is nil after derivation.



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/ancestor/spec/template.rb', line 62

def destination_pathname
  unless instance_variable_defined? :@destination_pathname
    @destination_pathname = nil

    if module_ancestor
      destination_pathname = module_ancestor.real_pathname

      unless destination_pathname
        # validate to derive real_path and therefore real_pathname
        module_ancestor.valid?

        destination_pathname = module_ancestor.real_pathname
      end

      @destination_pathname = destination_pathname
    end
  end

  @destination_pathname
end

#localsHash{Symbol => Object}

Local variables exposed to partials.

Returns:



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

def locals
  @locals ||= {
      metasploit_module_relative_name: metasploit_module_relative_name,
      module_ancestor: module_ancestor
  }
end

#overwriteBoolean

Whether to overwrite a pre-existing file.

Returns:

  • (Boolean)

    Defaults to false since nothing should write the template before the ancestor.



104
105
106
107
108
109
110
# File 'app/models/metasploit/model/module/ancestor/spec/template.rb', line 104

def overwrite
  unless instance_variable_defined? :@overwrite
    @overwrite = false
  end

  @overwrite
end

#search_pathnamesArray<Pathname>

Pathnames to search for partials.

Returns:



115
116
117
# File 'app/models/metasploit/model/module/ancestor/spec/template.rb', line 115

def search_pathnames
  @search_pathnames ||= DEFAULT_SEARCH_PATHNAMES.dup
end

#source_relative_nameString

Name of template under #search_pathnames without Spec::Template::EXTENSION.

Returns:



122
123
124
# File 'app/models/metasploit/model/module/ancestor/spec/template.rb', line 122

def source_relative_name
  @source_relative_name ||= DEFAULT_SOURCE_RELATIVE_NAME
end