Sha256: 3ba0a1dd65efffe63dbd7cd655e3ccb9d8c66c018c9a7e389023a52a5798c35b

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

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

class Unidom::Certificate::Certificating < Unidom::Certificate::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'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unidom-certificate-3.0 app/models/unidom/certificate/certificating.rb
unidom-certificate-2.1.2 app/models/unidom/certificate/certificating.rb
unidom-certificate-2.1.1 app/models/unidom/certificate/certificating.rb