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

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:



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

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:



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

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

  template.valid!
  template.write
end