Class: Mihari::Artifact

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/mihari/models/artifact.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Artifact

Returns a new instance of Artifact.



21
22
23
24
# File 'lib/mihari/models/artifact.rb', line 21

def initialize(attributes)
  super
  self.data_type = TypeChecker.type(data)
end

Instance Method Details

#unique?(ignore_old_artifacts: false, ignore_threshold: 0) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mihari/models/artifact.rb', line 26

def unique?(ignore_old_artifacts: false, ignore_threshold: 0)
  artifact = self.class.where(data: data).order(created_at: :desc).first
  return true if artifact.nil?

  return false unless ignore_old_artifacts

  days_before = (-ignore_threshold).days.from_now
  # if an artifact is created before {ignore_threshold} days, ignore it
  #                           within {ignore_threshold} days, do not ignore it
  artifact.created_at < days_before
end