Sha256: fd1969c5e38e3e4cf8b472102ed042980bee6dcbffb8df3e0f3436c6c835fd59

Contents?: true

Size: 792 Bytes

Versions: 3

Compression:

Stored size: 792 Bytes

Contents

module FinePrint
  class Signature < ActiveRecord::Base
    belongs_to :contract, inverse_of: :signatures
    belongs_to :user, polymorphic: true

    before_update { false } # no changes allowed

    validate :contract_published, on: :create

    validates :contract, presence: true
    validates :contract_id, uniqueness: { scope: [:user_type, :user_id] }
    validates :user, presence: true

    default_scope { order(:contract_id, :user_type, :user_id) }

    def is_explicit?
      !is_implicit?
    end

    protected

    ##############
    # Validation #
    ##############

    def contract_published
      return if contract.is_published?
      errors.add(
        :contract, I18n.t('fine_print.signature.errors.contract.not_published')
      )
      throw :abort
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fine_print-6.0.1 app/models/fine_print/signature.rb
fine_print-6.0.0 app/models/fine_print/signature.rb
fine_print-5.0.0 app/models/fine_print/signature.rb