Sha256: 112a3d81c2d3a153ce66611088375443637e955ae19854d68df19da66800a36f

Contents?: true

Size: 535 Bytes

Versions: 4

Compression:

Stored size: 535 Bytes

Contents

# frozen_string_literal: true

require "active_record"

class ArtifactValidator < ActiveModel::Validator
  def validate(record)
    return if record.data_type

    record.errors.add :data, "#{record.data} is not supported"
  end
end

module Mihari
  class Artifact < ActiveRecord::Base
    include ActiveModel::Validations
    validates_with ArtifactValidator

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

    def unique?
      self.class.find_by(data: data).nil?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mihari-2.1.0 lib/mihari/models/artifact.rb
mihari-2.0.0 lib/mihari/models/artifact.rb
mihari-1.5.1 lib/mihari/models/artifact.rb
mihari-1.5.0 lib/mihari/models/artifact.rb