Sha256: f21591b480458e0bc4d05bc0fa69317980583ef3b69533aeba4f2b881d80f9d0

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

##
# Certificating 是参与者和证书之间的认证关系。

module Unidom
  module Certificate

    class Certificating < ApplicationRecord

      self.table_name = 'unidom_certificatings'

      include Unidom::Common::Concerns::ModelExtension

      belongs_to :certificator,  polymorphic: true
      belongs_to :certificated,  polymorphic: true
      belongs_to :certification, polymorphic: true

      scope :certificated_by,  ->(certificator)  { where certificator:  certificator  }
      scope :certificated_is,  ->(certificated)  { where certificated:  certificated  }
      scope :certification_is, ->(certification) { where certification: certification }

      ##
      # 由认证者 certificator 用证书 certification 去认证的人或者机构 certificated ,认证时间是: opened_at。
      def self.certificate!(certification: nil, certificated: nil, certificator: nil, opened_at: Time.now)
        assert_present! :certification, certification
        assert_present! :certificated,  certificated
        assert_present! :opened_at,     opened_at

        attributes = { opened_at: opened_at }
        if certificator.present?
          attributes[:certificator] = certificator
        else
          attributes[:certificator_id]   = Unidom::Common::NULL_UUID
          attributes[:certificator_type] = ''
        end
        self.certification_is(certification).certificated_is(certificated).valid_at(now: opened_at).alive.first_or_create! attributes
      end

    end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Certificate::Certificating'

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-certificate-3.0.1 app/models/unidom/certificate/certificating.rb