Sha256: 1b536b39ce51bb8c11b123851f79610d2a5c7806af305b892d5b8caf292b9df8

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

module Unidom::Certificate::Concerns::AsCertification

  extend ActiveSupport::Concern

  included do |includer|

    has_many :certificatings, class_name: 'Unidom::Certificate::Certificating', as: :certification

    def certificate!(certificated, by: nil, at: Time.now)

      raise ArgumentError.new('The certificated argument is required.') if certificated.blank?
      raise ArgumentError.new('The by argument is required.'          ) if by.blank?
      raise ArgumentError.new('The at argument is required.'          ) if at.blank?

      certificatings.certificated_is(certificated).valid_at(now: at).alive.first_or_create! certificator: by, opened_at: at

    end

    def certificate?(certificated, at: Time.now)

      raise ArgumentError.new('The certificated argument is required.') if certificated.blank?
      raise ArgumentError.new('The at argument is required.'          ) if at.blank?

      certificatings.certificated_is(certificated).valid_at(now: at).alive.exists?

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-certificate-2.0 app/models/unidom/certificate/concerns/as_certification.rb