Sha256: 60499a9e9594255a48e418a38b372466b038bf6325f52c327a7ac2cf964dcbac

Contents?: true

Size: 1.44 KB

Versions: 50

Compression:

Stored size: 1.44 KB

Contents

class Mdm::Tag < ActiveRecord::Base
  include Metasploit::Model::Search

  #
  # Relations
  #

  # @!attribute hosts_tags
  #  Joins {#hosts} to this tag.
  #
  #  @return [ActiveRecord::Relation<Mdm::HostTag>]
  has_many :hosts_tags,
           class_name: 'Mdm::HostTag',
           dependent: :destroy,
           inverse_of: :tag

  belongs_to :user,
             class_name: 'Mdm::User',
             inverse_of: :tags

  #
  # Through :hosts_tags
  #

  # @!attribute [r] hosts
  #   Host that are tagged with this tag.
  #
  #   @return [ActiveRecord::Relation<Mdm::Host>]
  has_many :hosts, :through => :hosts_tags, :class_name => 'Mdm::Host'

  #
  # Search
  #

  search_attribute :desc,
                   type: :string
  search_attribute :name,
                   type: :string

  #
  # Validations
  #

  validates :desc,
            :length => {
                :maximum => ((8 * (2 ** 10)) - 1),
                :message => "desc must be less than 8k."
            }
  validates :name,
            :format => {
                :with => /^[A-Za-z0-9\x2e\x2d_]+$/, :message => "must be alphanumeric, dots, dashes, or underscores"
            },
            :presence => true

  #
  # Instance Methods
  #

  # Destroy this tag if it has no {#hosts_tags}
  #
  # @return [void]
  def destroy_if_orphaned
    self.class.transaction do
      if hosts_tags.empty?
        destroy
      end
    end
  end

  def to_s
    name
  end

  Metasploit::Concern.run(self)
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
metasploit_data_models-0.24.5 app/models/mdm/tag.rb
metasploit_data_models-0.24.1.pre.rspec.pre.3.pre.1 app/models/mdm/tag.rb
metasploit_data_models-0.24.1 app/models/mdm/tag.rb
metasploit_data_models-0.24.0 app/models/mdm/tag.rb
metasploit_data_models-0.23.3.pre.autoload app/models/mdm/tag.rb
metasploit_data_models-0.23.2 app/models/mdm/tag.rb
metasploit_data_models-0.23.2-java app/models/mdm/tag.rb
metasploit_data_models-0.23.1 app/models/mdm/tag.rb
metasploit_data_models-0.23.1-java app/models/mdm/tag.rb
metasploit_data_models-0.23.0 app/models/mdm/tag.rb
metasploit_data_models-0.23.0-java app/models/mdm/tag.rb
metasploit_data_models-0.22.8 app/models/mdm/tag.rb
metasploit_data_models-0.22.8-java app/models/mdm/tag.rb
metasploit_data_models-0.22.7 app/models/mdm/tag.rb
metasploit_data_models-0.22.7-java app/models/mdm/tag.rb
metasploit_data_models-0.22.6 app/models/mdm/tag.rb
metasploit_data_models-0.22.6-java app/models/mdm/tag.rb
metasploit_data_models-0.22.5 app/models/mdm/tag.rb
metasploit_data_models-0.22.5-java app/models/mdm/tag.rb
metasploit_data_models-0.22.4 app/models/mdm/tag.rb