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-2.0.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-1.1.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-1.0.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-1.0.1 lib/metasploit/model/spec/template/write.rb
metasploit-model-1.0.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.30.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.30.2-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.30.1 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.30.1-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.30.1.pre.rspec.pre.3.pre.1 lib/metasploit/model/spec/template/write.rb
metasploit-model-1.0.0.pre.rails.pre.4.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.30.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.30.0-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.29.2 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.29.2-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.29.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.29.0-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.28.0 lib/metasploit/model/spec/template/write.rb
metasploit-model-0.28.0-java lib/metasploit/model/spec/template/write.rb
metasploit-model-0.28.0.pre.engine.pre.requires lib/metasploit/model/spec/template/write.rb