Module: Metasploit::Model::Spec::Template::Write

Included in:
Module::Ancestor::Spec::Template, Module::Class::Spec::Template, Module::Instance::Spec::Template
Defined in:
lib/metasploit/model/spec/template/write.rb

Overview

Extend to add a class method to create a new template and write it only if valid.

Examples:

extend and write

class MyTemplate
  extend Metasploit::Model::Spec::Template::Write

  def write
    ...
  end
end

success = MyTemplate.write(attributes)

Instance Method Summary collapse

Instance Method Details

#write(attributes = {}) ⇒ true, false

Writes template for attributes to disk if the created template is valid.

Returns:

  • (true)

    if template was valid and was written.

  • (false)

    if template was invalid and was not written.

See Also:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/metasploit/model/spec/template/write.rb', line 21

def write(attributes={})
  template = new(attributes)

  written = template.valid?

  if written
    template.write
  end

  written
end

#write!(attributes = {}) ⇒ void

This method returns an undefined value.

Writes templates for attributes to disk if created template is valid; otherwise, raises an exception.

Raises:

See Also:



38
39
40
41
42
43
# File 'lib/metasploit/model/spec/template/write.rb', line 38

def write!(attributes={})
  template = new(attributes)

  template.valid!
  template.write
end