Sha256: 5b953e78a424cd228fb71ba85f56a20ec0fd35a4cc5ed5486ad31eaff5963289

Contents?: true

Size: 1 KB

Versions: 60

Compression:

Stored size: 1 KB

Contents

# Extend to add a class method to create a new template and write it only if valid.
#
# @example extend and write
#   class MyTemplate
#     extend Metasploit::Model::Spec::Template::Write
#
#     def write
#       ...
#     end
#   end
#
#   success = MyTemplate.write(attributes)
module Metasploit::Model::Spec::Template::Write
  # Writes template for `attributes` to disk if the created template is valid.
  #
  # @return [true] if template was valid and was written.
  # @return [false] if template was invalid and was not written.
  # @see #write!
  def write(attributes={})
    template = new(attributes)

    written = template.valid?

    if written
      template.write
    end

    written
  end

  # Writes templates for `attributes` to disk if created template is valid; otherwise, raises an exception.
  #
  # @return [void]
  # @raise [Metasploit::Model::Invalid] if template is invalid
  # @see write
  def write!(attributes={})
    template = new(attributes)

    template.valid!
    template.write
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
metasploit-model-5.0.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-5.0.1 lib/metasploit/model/spec/template/write.rb
metasploit-model-5.0.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-4.0.6 lib/metasploit/model/spec/template/write.rb
metasploit-model-4.0.5 lib/metasploit/model/spec/template/write.rb
metasploit-model-4.0.4 lib/metasploit/model/spec/template/write.rb
metasploit-model-4.0.3 lib/metasploit/model/spec/template/write.rb
metasploit-model-4.0.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-4.0.1 lib/metasploit/model/spec/template/write.rb
metasploit-model-4.0.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-3.1.4 lib/metasploit/model/spec/template/write.rb
metasploit-model-3.1.3 lib/metasploit/model/spec/template/write.rb
metasploit-model-3.1.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-3.1.1 lib/metasploit/model/spec/template/write.rb
metasploit-model-3.1.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-3.0.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-2.0.4 lib/metasploit/model/spec/template/write.rb
metasploit-model-2.0.3 lib/metasploit/model/spec/template/write.rb
metasploit-model-2.0.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-2.0.1 lib/metasploit/model/spec/template/write.rb