Sha256: a47f1317a267a6d33df65ee6e5e25585448fc0901f1f2b8dfd947e23d50e94a0

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

require 'metasploit/model/spec/template'

# 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

8 entries across 8 versions & 1 rubygems

Version Path
metasploit-model-0.27.3 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.27.3-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.27.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.27.2-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.27.1 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.27.1-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.27.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.27.0-java lib/metasploit/model/spec/template/write.rb